Need Help with Fortran compiler errors

  • Thread starter suezxc6
  • Start date
  • #1
suezxc6
11
0
Summary:: so I am trying to compile this program and i keep on getting "Unterminated character constant beginning at (1)" and "invalid character in name" at the months section. what do i have to change to fix it?

thanks

Fortran:
program Lab6

implicit none



character*9 month

integer monthNum, pos



character*108 months



months = "January       February March       April     &

                  &May             June         July           August  &

                  &SeptemberOctober November December "



print*, "Enter the month name"

read*, month



pos = index(months,month)

if (pos .eq. 0) then

print*, "The month is invalid"

else

monthNum = pos/9 + 1

! process day

print*, month, " is month #", monthNum

print*, "now process day"

end if



stop

end
<Moderator's note: code tags added>
 
Last edited by a moderator:

Answers and Replies

  • #2
DrClaude
Mentor
8,127
4,948
I added code tags to your post, but you will need to repost to get the spacing correct.

I see nothing wrong, assuming that the blank lines 18 and 20 are not really present. Which compiler are you using?
 
  • #3
suezxc6
11
0
GNU. And there are no blank lines present. At line 17 i get "Unterminated character constant beginning at (1)" then at 19 and 21 i get "invalid character in name".
 
  • #4
DrClaude
Mentor
8,127
4,948
I have no problem compiling it with gfortran. Can you show the compile command you are using?
 
  • #5
anorlunda
Staff Emeritus
Insights Author
11,207
8,623
You may have an invisible character, such as ESC, in the source code. How that happened and how you get rid of it I don't know.
 
  • #6
suezxc6
11
0
a.png

this is what it looks like.
 
  • #7
DrClaude
Mentor
8,127
4,948
The file extension needs to be f90, since you re using that variant of Fortran.
 
  • Like
Likes berkeman and jedishrfu
  • #8
suezxc6
11
0
Thanks, it works!
I'm new to fortran and this is all still pretty confusing. Is there by any chance a fortran for dummies book i could buy online somewhere? With lectures being canceled I am going to need all the help i can get
 
  • #9
suezxc6
11
0
ok sorry yall. its me again and i need help with this exercise.
I have to write a program that will output the astrological signs for given birthdays. It will have to read a date in a given format and after a simplified validity check it has to determine the corresponding astrological sign. So if i wrote September 21 it has to output virgo. I'm getting a lot of errors and also having a hard time with the part i italicized.

program Lab6
implicit none

character*1 reply

do
print*, "Do you want to convert a date, Y or N?"
read*, reply
if (reply .eq. "N" .or. reply .eq. "n") exit
print*, "process a date"

character*9 month
integer monthNum, pos, day

character*36 months1 / "January February March April "
character*36 months2 / "May June July August "
character*36 months3 / "SeptemberOctober November December "

character*108 months

integer lastDay(12) / 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 /

integer splitDay(12) / 19,18,20,19,20,20,22,22,22,22,21,21 /

character*11 astroSign(12) / "Capricorn", "Aquarius",
x "Pisces", "Aries", "Taurus", "Gemini", "Cancer",
x "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius" /

months = months1 // months2 // months3

print*, "Enter the month name"
read*, month

pos = index (months, month)
if (pos .eq. 0) then
print*, "The month is invalid"
else
monthNum = pos/9 + 1
monthNum = mod(monthNum, 12)+1
print*, "Enter the day"
read*, day
if (invalid day for the given month) then
print*, "The day is invalid"
else
adjust monthNum to align with astrological sign
print*, "The astrological sign is: ", astroSign(monthNum)
end if
end if

end do
stop
end
 
  • #10
DrClaude
Mentor
8,127
4,948
I suggest you make an array of months as you did for the astrological signs. This will make string comparison easier and you can also more easily convert the month into a number.

Think of how you would do things yourself, with a calendar you are not familiar with. First, you would check to see if the month is part of the list of valid months, then if the day is a valid number for that month. I let you figure out how you would then figure out the corresponding star sign. This is the basis of algorithms: decompose the big task into smaller tasks.
 
  • #12
DrClaude
Mentor
8,127
4,948
@suezxc6 Please use code tags (>_ Inline code in the dropdown menu) when posting code:
Screen Shot 2020-03-20 at 13.06.51.png
I have also moved the thread to the homework forum.
 
  • #13
FactChecker
Science Advisor
Homework Helper
Gold Member
7,737
3,399
FORTRAN can be very space and column dependent. You need to use the code tags (see the '</>' tag at the top of the edit window) to keep those exactly like your program code or it will not be possible to get help.
 

Suggested for: Need Help with Fortran compiler errors

Replies
2
Views
367
  • Last Post
Replies
7
Views
690
Replies
4
Views
1K
  • Last Post
Replies
15
Views
656
  • Last Post
Replies
1
Views
263
  • Last Post
Replies
0
Views
669
Replies
8
Views
706
Replies
3
Views
494
Replies
2
Views
427
Top