Reading from text file

I have edited the program and it seems the first Frequency value from my text file is being read and not the rest. How can I create a loop that will keep reading from the text file and display different values for Frequency and Velocity and not same values? For Time, since it is an increment of 100 a loop worked without calling the time from the text file which is not correct as it should read from the text file in a loop. Also, Frequency values are long decimal points not displayed as seen with 9 decimal point since am using double data type. my text file loops like this:
0

100

200

300

400

500

600

5.500000040

5.500000095

5.500000230

5.500001800

5.500000870

5.500000065

5.500000370

Problem:
For a radar transmitting at frequency f (t), the difference in transmitted and received frequencies due to a target moving at speed v (m/s) relative to the radar that is, directly toward or away from the radar is given by

(f (r)- f (t)) / f (t) = 2v/c

where f (r) is the received frequency and c is the speed of light (3x10^8m/s). A weather service station at a major municipal airport is using a C-band Doppler radar f (t) = 5.5GHz). During a severe thunderstorm, the following received frequencies are observed:

Time(s) Frequency (GHz)
0 5.500000040
100 5.500000095
200 5.500000230
300 5.500001800
400 5.500000870
500 5.500000065
600 5.500000370

Write a program that scans these data and displays a table showing the data along with a third column displaying the Doppler velocities of the winds relative to the radar.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  #include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int n;
	int Time = 0;
	double Frequency;
	double Velocity = 0;//size of array more than number of entries in data file

	ifstream infile("C:\\My documents\\frequency.txt", ios::in);//open the text file
	infile >> Time;
	infile >> Frequency;
	while (!infile.eof())
	{

		infile >> Frequency;
		Velocity = (((Frequency - 5.5) / 5.5) * 3e+8) / 2;
		Frequency++;
	}
	cout << setw(1) << "Time" << setw(15) << "Frequency" << setw(20) << "Velocity" << endl;
	for (Time = 0; Time < 700; Time)//counter loop of the first values from 0 to 600 increment
	{
		cout << setw(1) << Time << setw(15) << Frequency << setw(20) << Velocity << endl;
		Time += 100;//Print out for the table with values.
	}

	infile.close();//input file is closed.
	system("PAUSE");//will wait for the user to end the console
	return 0;//End of the main program
}
Is your input file really like:
time1
time2
..
timeN
freq1
freq2
..
freqN

If so, you would have to know N before reading the file.

Things are much simpler, if the file actually has:
time1
freq1
time2
freq2
..
timeN
freqN
I changed the file like above and now not printing anything.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
5.500000040
100                        
5.500000095
200                           
5.500000230
300                           
5.500001800
400                           
5.500000870
500                           
5.500000065
600 
5.500000370
  










I thought the input file looked like this:
0 5.500000040
100 5.500000095
200 5.500000230
300 5.500001800
400 5.500000870
500 5.500000065
600 5.500000370
and hence the program needs to repeatedly read the two values, time and frequency.

As a suggestion, it's not a good idea to change the input file, it's just adding more uncertainty. Try to keep things nailed down firmly and the target will be easier to hit.
Topic archived. No new replies allowed.