I'm brand new to this and I don't know why my program (posted below) only reads the last line of data from the input file. Our assignment is to write this program with a while loop that terminates when there's no more data in the file. Why does it skip down to the last line of data in the file? It skips the first four lines and only picks up the last line. I've checked that the input file is OK.
We have to use the value-returning functions, too.
Here's my program. Please tell me where I'm not getting it. I've been stuck on this for hours.
The input section reads a radius on line 45, then repeatedly reads in radii in the loop afterward, repeatedly overwriting the old "radius" value until it reaches the end of the input file. Then it calculates the area and circumference once, then starts printing in a loop that doesn't run as infile is already at the end of file.
Zhuge, thank you for telling me the concept of the problem. I get what it's doing now, but I don't know how to code it so it won't overwrite. Can you help me with fixing the code? Thanks millions for helping me start to see the problem. I'm totally neo at this!
Zhuge, we don't even use infile.good in our class yet! Here's my latest try, but it's more messed up than ever. I understand your concepts, but I can't seem to get them down in code. Now I don't know what it's reading in the file, but it's still only putting out one line.
I'm gonna keep trying, but if you can think of a way to break it down even simpler for a programming midget like me, then I'd appreciate it. But already you've helped me so much by showing me what I need to try to figure out.
With both Zhuge's and my teacher's help, I figured out the basic concept of what I was doing wrong. My teacher showed me corrections for my program. Following is the new program.
But get this: Now, for some reason I can't figure out, it only reads every other line. It skips the first line, reads the second, skips the third, etc. How can that happen? I've verified that the input file is valid.
Can someone please give me an idea of why it's skipping every other number?