我正在编写一个Fortran代码,以计算每门3学分的5门课程的学生的GPA,我尝试使用IF语句,但出现错误
The condition in an IF statement should be scalar
在下面找到我的代码。
program cgpa
implicit none
! This program calculates gp
character, dimension (5) :: grade
character :: name*50
integer :: i
real :: gp, tcp
print *," input student's name"
read*, name
print*, " student's grade"
tcp = 0.0
do i = 1, 5
read *, grade(i)
if (grade == "a") then
tcp = tcp + 15
end if
if (grade == "b") then
tcp = tcp + 12
else if (grade == 'c') then
tcp = tcp + 9
else if (grade == 'd') then
tcp = tcp + 6
else if (grade == 'e') then
tcp = tcp + 3
else if (grade == 'f') then
tcp = tcp + 0
else
print *, "error type correct grade"
end if
end do
gp = tcp / 15
print *, "dear " , name, " your GP is"
print *, gp
print *, " your grades are "
print*, grade
end program cgpa