Need Help with Fortran compiler errors

AI Thread Summary
The discussion revolves around resolving Fortran compiler errors, specifically "Unterminated character constant" and "invalid character in name." The user encountered these issues while compiling a program that processes month names and astrological signs. It was suggested that the user might have invisible characters in their code and that the file extension should be .f90 for compatibility. Additionally, recommendations were made to simplify string comparisons by using arrays for months and astrological signs, and resources for learning Fortran were shared. The user expressed a need for beginner-friendly materials to aid their understanding of Fortran programming.
suezxc6
Messages
11
Reaction score
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:
Physics news on Phys.org
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?
 
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".
 
I have no problem compiling it with gfortran. Can you show the compile command you are using?
 
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.
 
a.png

this is what it looks like.
 
The file extension needs to be f90, since you re using that variant of Fortran.
 
  • Like
Likes berkeman and jedishrfu
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
 
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
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.
 
  • #11
  • #12
@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
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.
 
Back
Top