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

Click For Summary

Discussion Overview

The discussion revolves around a Fortran programming assignment focused on reading and sorting student grades, with a specific issue related to an integer overflow error encountered during execution. Participants explore the structure of the code, particularly the use of nested loops and the handling of student data.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant reports an integer overflow error on a specific line of their Fortran program and seeks assistance.
  • Questions are raised about the return values of functions M1(x) and M2(x), with some uncertainty about their purpose and implementation.
  • Another participant critiques the nested 'do while' loops, expressing confusion about their structure and questioning whether they will terminate correctly.
  • Concerns are mentioned regarding the readability of the code, suggesting that meaningful variable names and comments could improve understanding.
  • A participant reflects on their learning process, noting that they eventually resolved their looping issue and successfully ran the program, while expressing gratitude for the feedback received.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the specific cause of the integer overflow error, and multiple interpretations of the code structure and logic remain. The discussion includes both critiques and suggestions without a definitive resolution.

Contextual Notes

There are limitations in understanding the code due to the lack of clear variable names and comments, which may affect the clarity of the logic and the source of the error. The specific conditions under which the integer overflow occurs are not fully explored.

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
 
Technology 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
 

Similar threads

  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
26
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 15 ·
Replies
15
Views
5K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 25 ·
Replies
25
Views
10K