Why is my output giving garbage values?

Why does my output come out with all the garbage values at the end?

My code shows my class, part of the main body, and the function that i know has an issue but i'm not sure what, can anyone help?

**EDIT** I edited the code so it's easier to understand what I mean

Last edited on
hiya,
I'm not sure why this is even compiling for you:
 
infile.open("data.txt");


You haven't defined what infile is? Even if you had, you appear to be opening a file, closing it at the end, but doing nothing with it in the middle.
I suspect this isn't your up to date code?
Last edited on
Hi,

Some questions for you:

What are the values stored in your variables?

Grab a pen & paper, mentally step through you program 1 line at a time & write down the value that is stored in each variable at that time.

Think about the process for class variables - how are they initialised?

How many times does the for loop run?

Did you check that opening the file worked?

Did you read any values from the file?

There you go, some stuff to think about :+D

Edit: Also think about the names you have used for variables & classes - I find them confusing.
Last edited on
@mutexe I didn't post my full code, no worries i have defined infile.open(), i guess when i was copying and pasting the parts i wanted to post i accidentally left that out.

@TheIdeasMan thanks for ur advice but as to your questions, all of them have answers, once again this isn't the full code. I saw no reason to post the whole thing because then you would be spending too much time on things that didnt have the error.

The loop runs 2 times. first for child[0] and second for child[1]. I know there's an error in function lettergrade() b/c as you can see an average of 74 is not an A and an average of 91 is not i with an accent.

I just don't know where i went wrong.
Last edited on
Line 18 sets n=0. Line 44 loops while i<n. Since the initial value of i is 0, the loop won't execute. But if it did you'd still have problems

1
2
             if (child[i].name.avg <=90){
                  child[i].name.lettergrade = 'A';

Damn! I wish I got an A for any grade that was less 90 or less! :)

else if (child[i].name.avg <=80 && child[i].name.avg >= 89){
Please give an example of an number that is less than or equal to 80 and greater than or equal to 89.

The same problem is in most of the other comparisons.

Last edited on
ooh ok i see my error now, thank you :)
so now that that is fixed my output looks like this:


                Grade Book

Student         Grades                  Average                 Letter Grade
John Apple      73 57 94                74.6667                 C
Mary Seed       99 85 89                91                      A
        3.78835e-317 6.94719e-308 2.30353e-306          7.91e-307
        F
        3.94625e-317 3.94642e-317 1.43417e-304          4.78056e-305
        F
        1.91296e+124 1.55401e+124 1.59886e+124          1.68861e+124
        A
        4.94066e-322 0 1.49222e+124             4.97405e+123
A
        0 1.32689e-317 1.96549e+124             6.55164e+123
A
        2.12943e-312 0 0                7.09811e-313                    F
        4.94066e-324 5.12181e+303 6.94976e-308          1.70727e+303
        A
        5.1111e+303 1.86906e-306 2.31404e-306           1.7037e+303
        A
        1.22595e+269 1.86906e-306 6.94867e-308          4.08651e+268
        A
        1.08858e-311 1.89481e-306 2.30707e-306          1.40063e-306
        F
        6.94979e-308 1.86906e-306 6.94979e-308          6.69353e-307
        F
        1.89481e-306 2.90717e-312 6.95025e-308          6.54772e-307
        F
        0 5.43231e-312 1.3602e-311              6.34477e-312
F
        2.30558e-306 0 -7.29202e-304            -2.42299e-304
F
        2.30707e-306 2.32571e-311 5.14162e-263          1.71387e-263
        F
        1.20675e+269 4.34585e-311 2.30707e-306          4.0225e+268
        A
        2.71618e-312 1.15482e+269 -1.#QNAN              -1.#QNAN
        ♦
        4.17201e-309 6.95274e-308 6.36806e-314          2.45665e-308
        F
        1.15267e-318 6.12557e+293 4.18059e-309          2.04186e+293
        A
        4.17201e-309 1.15256e-318 6.12583e+293          2.04194e+293
        A
        6.95184e-308 4.17864e-309 6.12603e+293          2.04201e+293
        A
        8.38727e-307 4.95104e-309 1.69761e-313          2.81226e-307
        F
        1.28825e-231 6.9521e-308 7.35917e-314           4.29416e-232
        F
        8.38727e-307 3.95253e-323 1.7969e-313           2.79576e-307
        F
        4.24399e-314 7.29112e-304 3.39519e-313          2.43037e-304
        F
        1.20605e+269 9.93041e-315 4.95036e-309          4.02018e+268
        A
        1.51276e+261 4.08889e-315 0             5.04253e+260
A
        1.63287e+261 -1.#QNAN 1.57621e+261              -1.#QNAN
        8
Press any key to continue . . .
Last edited on
@TheIdeasMan thanks for ur advice but as to your questions, all of them have answers, once again this isn't the full code. I saw no reason to post the whole thing because then you would be spending too much time on things that didnt have the error.


Well .... perhaps you could read through my questions again, and think about them in a bit more detail.

I can see from the output that you haven't initialised variables. Do you have constructors for your classes?

Just post the full code, then we can see what is going on.

Cheers :+)
Topic archived. No new replies allowed.