Nov 3, 2012 at 8:24pm Nov 3, 2012 at 8:24pm UTC
Kind of hard to do my homework if the teacher's example was wrong....
Nov 3, 2012 at 8:26pm Nov 3, 2012 at 8:26pm UTC
what's the homework?
Correct the program?
Last edited on Nov 3, 2012 at 8:26pm Nov 3, 2012 at 8:26pm UTC
Nov 3, 2012 at 8:26pm Nov 3, 2012 at 8:26pm UTC
It won't run for me because I don't have the input file "dropout115.txt ".
Do you have sample input data for testing purposes?
Nov 3, 2012 at 8:30pm Nov 3, 2012 at 8:30pm UTC
The program is to read the file dropout115.txt and display the information in a terminal console. The first number is the number of students (numStudents) and the 2nd number is the number of dropouts (numDropouts).
Nov 3, 2012 at 8:34pm Nov 3, 2012 at 8:34pm UTC
looks like you don't have the file "dropout115.txt in the right location
Nov 3, 2012 at 8:35pm Nov 3, 2012 at 8:35pm UTC
it's giving me the proper output, what are you using to compile?
Well, when I ran it with "dropout115.txt" having no data, it returned the same values you are outputting. Once I put in the sample data
it gave me the correct output.
Last edited on Nov 3, 2012 at 8:37pm Nov 3, 2012 at 8:37pm UTC
Nov 3, 2012 at 8:37pm Nov 3, 2012 at 8:37pm UTC
I'm using codeblocks. I have the txt file in the same folder as the cpp file. Is that wrong, its worked for all my other programs.
Nov 3, 2012 at 8:39pm Nov 3, 2012 at 8:39pm UTC
well you're not triggering the
cout << "The file could not be opened." << endl;
so it seems like your file is opening, you have that sample data in the "dropout115.txt"?
Nov 3, 2012 at 8:44pm Nov 3, 2012 at 8:44pm UTC
yes, its just like it is on the first post. I am doing this in ubuntu. Could that have anything to do with it, I'm a new ubuntu user.
Nov 3, 2012 at 8:46pm Nov 3, 2012 at 8:46pm UTC
If the file is in the wrong location, you will get the error message, "The file could not be opened."
Perhaps there are several different copies of the input file, containing different data?
With the correct file, the program works ok for me.
Last edited on Nov 3, 2012 at 8:46pm Nov 3, 2012 at 8:46pm UTC
Nov 3, 2012 at 8:47pm Nov 3, 2012 at 8:47pm UTC
Nope I'm pretty sure I only put one txt file in the folder with it called dropout115.
Nov 3, 2012 at 8:47pm Nov 3, 2012 at 8:47pm UTC
Is anyone trying this on a linux based machine?
Nov 3, 2012 at 8:50pm Nov 3, 2012 at 8:50pm UTC
I am now. Was doing it on a VM with Visual Studios and it worked great. I then tried it on Xcode on my Mac and found the possible issue. Put in the full location of the file "dropout115.txt".
ie. "/Documents/Cpp/ReadFrom/dropout115.txt"
dropout.open("/Users/Documents/Cpp/ReadFrom/dropout115.txt" , ios::in);
Last edited on Nov 3, 2012 at 8:51pm Nov 3, 2012 at 8:51pm UTC
Nov 3, 2012 at 8:53pm Nov 3, 2012 at 8:53pm UTC
Nope still getting the same output.
Nov 3, 2012 at 8:54pm Nov 3, 2012 at 8:54pm UTC
k, I'm pulling up my Backtrack VM right now, going to put codeblocks on there and try it also, give me a few.
Nov 3, 2012 at 8:58pm Nov 3, 2012 at 8:58pm UTC
lol, I'm a bit of a Cpp newb, I have no idea. I just know that I got -nan as an output when I had no data in the "dropbout115.txt".