We're learning how to input text files. This assignment is to find the median of a sequence of numbers (ordered).
I'm able to read in the data once, to give me a list lf the numbers. Great. Next, I need to read in the data again so I can find the number at a specific position. The way I'm doing it now is to reopen the file and use a FOR LOOP to go through the inputs until I reach the input at the position I desire.
The problem is that it won't let me do that. It keeps giving me an unexpected end of file error. I don't know why this is happening, because I'm closing the file and then reopening it.
Any suggestions would be appreciated.
Here's the code; Hopefully the formatting won't get screwed up. heh
#include <iostream.h>
#include <fstream.h>
#include <cmath>
#include <iomanip.h>
double input, total;
int position1, position2, position, count, count1;
int main()
{
//**************
//* INITIALIZE *
//**************
double middle;
count = 0;
count1 = 0;
middle = 0;
//------------
//| Greeting |
//------------
cout << "Welcome to Warren's Median Evaluator! \n\n";
//-----------------
//| Open the file |
//-----------------
ifstream fin;
fin.open("C:\\Program Files\\Microsoft Visual Studio\\MyProjects\\A3 Part 1a\\even.dat");
Question
deck
We're learning how to input text files. This assignment is to find the median of a sequence of numbers (ordered).
I'm able to read in the data once, to give me a list lf the numbers. Great. Next, I need to read in the data again so I can find the number at a specific position. The way I'm doing it now is to reopen the file and use a FOR LOOP to go through the inputs until I reach the input at the position I desire.
The problem is that it won't let me do that. It keeps giving me an unexpected end of file error. I don't know why this is happening, because I'm closing the file and then reopening it.
Any suggestions would be appreciated.
Here's the code; Hopefully the formatting won't get screwed up. heh
Link to comment
Share on other sites
2 answers to this question
Recommended Posts