I have to read and analyze a file called Random.rtf full of random numbers. The output of my program is:
File Random.rtf is open.
Number of Numbers: 0
Sum of Numbers: 0
Average of Numbers: nan
Largest Number: 0
Smallest Number: 1001
Second Largest Number: 0
Second Smallest Number: 1001
Am I doing something wrong in my code? I have confirmed that my file is opening I just can't get it to read any numbers from it.
RTF files are not simple text files. They contain a load of formatting info in them. Try to open rtf file with notepad and you will see what it really contains.
I got a .txt file and it is working but theres a bug. It doesn't calculate the second largest number right. I think the same thing is wrong with the second smallest but it just incidentally got the right value.
The problem with the way I have it is that when it gets to the actual second max (987) that is the largest number so the program assigns that to big_num so big_num2 can't take that value on. 1000 is the largest value but that doesn't come up until much later in the file.
Pretty sure this would work, but try it out and let me know haha... and actually maybe you can use this to simplify your if statements a bit. You might not even need the last one, and you may be able to eliminate the 2nd to last by modifying the one right after the first if like this one.