Reading the next line
Apr 25, 2012 at 2:56pm UTC
I have a nearly completely functional bit of code, with one roadblock due to my lack of experience. This code is supposed to read from a file and tell what the general state of a person's blood pressure is.
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
char yes;
ifstream myfile;
string lastname;
string firstname;
int sys;
int dia;
myfile.open ("patient.dat" );
myfile >> lastname>>firstname>>sys;
myfile.ignore(1,'/' );
myfile >> dia;
do { if (sys<=119 && dia <=79)
cout << lastname << ", " << firstname << " has normal blood pressure at " << sys <<"/" << dia <<endl;
else if (sys>= 120 && sys<=139 || dia>=80 && dia<=89)
cout << lastname << ", " << firstname << " has prehypertension at " << sys <<"/" << dia <<endl;
else if (sys>= 140 && sys<=159 || dia>=90 && dia<=99)
cout << lastname << ", " << firstname << " has Stage 1 high blood pressure at " << sys <<"/" << dia <<endl;
else cout << lastname << ", " << firstname << " has Stage 2 high blood pressure at " << sys <<"/" << dia <<".\n" ;
cout<< "Next patient? Y/N " ;
cin>>yes;} while (yes=='y' || yes=='Y' );
return 0;
}
My issue arises in that I do not know how to make it read the next line in the data file, which looks like this:
1 2
Smith Eli 110/73
Johns Thomas 200/78
And so on til the end of the file.
Can I get any help?
Last edited on Apr 25, 2012 at 2:56pm UTC
Topic archived. No new replies allowed.