I have a text file in the form
5502 5202.3
1523 2536.1
1254 1256.2
17846 8956.2 and so on
left one is time and right one is pressure, I need to show the time value as it is but i need to use the pressure value to calculate air speed.
I don't know how to use the strings to pick up the list properly. I did the calculation formula for the air speed but i can't pick the pressure value up from the text file.
here's what i did:
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main()
{
int number_of_lines = 0;
int time;
double Pt;
double ao = 0;
double P0 = 1013.25;
double Cas;
double A;
double B;
double C;
double D;
int n=0;
float X = 2 / 7;
string line;
ifstream myfile("code.txt");
while (getline(myfile, line))
{
++number_of_lines;
}
/* I NEED HELP IN THIS PART TO TAKE THE PRESSURE VALUE FOR CALCULATION LATER, LIKE A LOOP AND IN THE RESULT I NEED TO DISPLAY TIME VALUE WITH CALCULATED AIR SPEED VALUE IN THE SAME FORMAT. */
ifstream file("code.txt");
string s;
while (n < number_of_lines && file >> time >> s >> Pt )
{
n++;
cout << time<<endl;
}
A = Pt / P0;
B = A + 1;
C = pow ( B , X);
D = 5 * (C - 1);
Cas = ao * (sqrt(D));
cout << Cas;
return 0;
system("pause");
}
Im new but I believe you declared and opened the file wrong. So I don't think it is reading your file at all. Also make sure the file is in the same place as your project.
Your declare should be: ifstream myfile;
To open the file: myfile.open("code.txt");
Try that and see if it works. Im in my first semester so I might be wrong, but Im pretty sure.
umm, thanks for the reply. but the command you said isn't working . I am getting errors. My program is working fine , i am getting output as
5502
5202.3
1523
2536.1
1254
1256.2
...
If you group your values in the text file into threes every second one is put into s and every third one is put into Pt and neither of those is printed to console.
Also Cas should always print 0 to console since ao is always 0.
Put your airspeed calculation inside the while loop.