Integer overflow on assignment

In summary, the program was not able to print the grades in alphabetical order because there was an integer overflow on line 87.
  • #1
joao_mart
3
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
  • #2
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:
  • #3
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.
 
  • #4
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 joao_mart
  • #5
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
 

1. What is an integer overflow on assignment?

An integer overflow on assignment occurs when a value that is too large to be stored in a particular integer data type is assigned to that variable. This can result in unexpected behavior and can lead to errors in the program.

2. How does an integer overflow on assignment happen?

Integer overflow on assignment happens when the assigned value is larger than the maximum value that can be represented by the data type. For example, if a variable of type "short" can hold values up to 32767, assigning a value of 40000 to it will result in an overflow.

3. What are the consequences of an integer overflow on assignment?

The consequences of an integer overflow on assignment can vary depending on the programming language and the specific implementation. In some cases, it may result in the value being truncated or wrapped around to a negative value. This can lead to incorrect calculations or unexpected behavior in the program.

4. How can integer overflow on assignment be prevented?

To prevent integer overflow on assignment, it is important to understand the maximum values that can be stored in each data type and ensure that the assigned values do not exceed these limits. Additionally, some programming languages have built-in functions or libraries that can detect and handle integer overflows.

5. Can an integer overflow on assignment be beneficial?

In most cases, integer overflow on assignment is considered a programming error and should be avoided. However, there may be rare instances where it can be used intentionally, such as in cryptography algorithms. In these cases, it is important to carefully handle the overflow and ensure that it does not lead to unexpected behavior or security vulnerabilities.

Similar threads

  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
11
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
Replies
10
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
Replies
26
Views
5K
  • Programming and Computer Science
Replies
4
Views
8K
  • Programming and Computer Science
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
Back
Top