Why Does My Fortran Program Have an Integer Overflow on Assignment?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
joao_mart
Messages
3
Reaction score
0
Hey guys, I have an assignment on fortran, which basically is supposed to read grades of a class and print them in alphabetical order and wether if the student failed or passed the class. We're supposed to do everything using our basic knowledge of fortran.
When I run it it says 'integer overflow on line 87'. Can anyone help me out?
Link for the program:
http://pastebin.com/naZpzCA2
http://pastebin.com/NnARY1Mu - example of what the program reads
PS.: All the names are in portuguese
 
Physics news on Phys.org
I have some questions, what are the return values of M1(x) or M2(x) ? also I am not sure why you use so many do while G<i ... is it safe without incrementing it?
 
Last edited:
ChrisVer said:
I have some questions, what are the return values of M1(x) or M2(x) ? also I am not sure why you use so many do while G<i ... is it safe without incrementing it?
I did all the do while g<i because the program has to read grades of 5 classes. My bad, i uploaded one with only 3 classes.
I'm not sure what you meant by return values, but the M1 is supossed to read all the students 'Registrations', and M2 is a array for all the students names.
 
joao_mart said:
I did all the do while g<i because the program has to read grades of 5 classes.
Correct me if I'm wrong but I read something like:
Code:
G=0
do while G <= 5
  do while G<=4
     do while G<=3
        do while G<=2
           do while G<=1
                 [your code]
                 G= G+1
          enddo
       enddo
    enddo
  enddo
enddo
it looks pretty weird as a construct, in fact I am not sure how it's ever going to leave G<=2, but maybe I am misreading your code.

I meant before checking in the referenced line the condition M2[I ]<M2[J], you could try to print them out and see what is being checked? just by looking at the type of error you get, it's an error that appears when the integer type is very long to be represented; and for students' matrikulation numbers that is weird.
Maybe [I am not a fortran expert] there is something wrong when I=A , and J=I+1 to A...
An auxilary comment is that it would be easier to read your code if you gave your variables meaningful names for a second party reader, who reads your code, understands what they are...and supply some comments between your code?
 
Last edited:
  • Like
Likes   Reactions: joao_mart
ChrisVer said:
Correct me if I'm wrong but I read something like:
Code:
G=0
do while G <= 5
  do while G<=4
     do while G<=3
        do while G<=2
           do while G<=1
                 [your code]
                 G= G+1
          enddo
       enddo
    enddo
  enddo
enddo
it looks pretty weird as a construct, in fact I am not sure how it's ever going to leave G<=2, but maybe I am misreading your code.

I meant before checking in the referenced line the condition M2[I ]<M2[J], you could try to print them out and see what is being checked? just by looking at the type of error you get, it's an error that appears when the integer type is very long to be represented; and for students' matrikulation numbers that is weird.
Maybe [I am not a fortran expert] there is something wrong when I=A , and J=I+1 to A...
An auxilary comment is that it would be easier to read your code if you gave your variables meaningful names for a second party reader, who reads your code, understands what they are...and supply some comments between your code?
Thanks a lot for the help. I spent some time and finally figured out that the type of loop that I was trying to do wasn't possible with the commands I was using. but i got the program to run perfectly in the end. Thanks so much for the help and advices, i really appreciate the time you spent trying to understant my horrible code xD