As I tried to point out before, you need to change this:
1 2 3 4 5 6 7 8 9
|
infile >> Time;
infile >> Frequency;
while (!infile.eof())
{
infile >> Frequency;
Velocity = (((Frequency - 5.5) / 5.5) * 3e+8) / 2;
Frequency++;
}
| |
to this:
1 2 3 4 5 6 7
|
while (infile >> Time >> Frequency)
{
double Velocity = Velocity = (((Frequency - 5.5) / 5.5) * 3e+8) / 2;
// Output the values of Time and Frequency which were read from the file
// and the calculated Velocity.
}
| |
Well, you could adapt your code, but please don't use
eof()
here, it is almost always wrong to use eof() in a while loop. The result, adapting your current version would look lile this, but notice it is longer and more complicated. I tried to show you the simple way.
1 2 3 4 5 6 7 8 9 10
|
infile >> Time;
infile >> Frequency;
while (infile)
{
Velocity = (((Frequency - 5.5) / 5.5) * 3e+8) / 2;
// Output the values of Time and Frequency which were read from the file
// and the calculated Velocity.
infile >> Time;
infile >> Frequency;
}
| |
Also, get rid of the
for
loop, it is nonsense. And also as i mentioned, output the heading line
before the while loop which reads the file. Why? Because that loop will be where you print out the results, so it's no use printing out the headings
afterwards. Also don't do this:
Frequency++;
, it doesn't make any sense to do that.