Mar 27, 2012 at 8:23pm UTC
I am trying to loop my infile and readings correctly. right now i am only getting 4 of the data sets in my output. I am not sure about how to go about the loop file. the bold is what goes inside of my infile. under that is my code. None of the code is broken . Im just trying to get a loop to output all of the data in the file.
Jones C 3
60 124 130 84
65 121 133 80
70 120 130 81
Smith N 1
30 195 120 85
Williams F 2
45 185 190 112
50 181 193 115
Foster R 4
55 165 163 115
65 145 167 95
57 165 163 105
59 163 165 108
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
ifstream mydata;
void evaluate_cholesterol(int hdl_reading, int ldl_reading, string &
hdl_evaluation, string & ldl_evaluation); // function prototype
void evaluate_blood_pressure(int systolic_reading, int disastolic,
string & diastolic_evalutation, string & systolic_evaluation); // function prototype
int main()
{
int count = 1;
int rows; // declaring variables
float ratio;
char type;
string name, eval1, eval2, leval, heval, interp;
float num_ofrecords, hdl, ldl, dis, sys;
cout << "Enter the number of patient records: "; // prompt user
cin >> num_ofrecords; // collecting data
cout << endl;
while (mydata) // confused i believe this is where the problem is
{
mydata.open("infile.txt"); // opening file
mydata >> name >> type >> rows;
cout << " Current Patients Name- " << name << endl;
mydata >> hdl >> ldl >> sys >> dis;
ratio = (hdl / ldl);
cout << endl;
cout << "Data Set :" << endl;
cout << "Cholesterol Profile " << endl;
cout << " HDL: " << hdl << " LDL: " << ldl << endl;
cout << fixed << showpoint << setprecision(4);
cout << " Ratio: " << ratio << endl;
{
if (ratio > 0.3) // Ratio HDL/LDL Interpretation
{
interp = "good";
}
else if (ratio <= 0.3)
{
interp = "not good";
}
}
cout << fixed << showpoint << setprecision(0);
evaluate_cholesterol(hdl, ldl, leval, heval);
cout << " HDL is " << leval << endl; // displaying data
cout << " LDL is " << heval << endl;
cout << " Ratio of HDL to LDL is " << interp << endl;
cout << "Blood Pressure Profile " << endl;
cout << " Systolic: " << sys << " Diastolic: " << dis << endl;
evaluate_blood_pressure(sys, dis, eval1, eval2);
cout << " Systolic reading is " << eval2 << endl;
cout << " Diastolic reading is " << eval1 << endl;
cout << endl;
}
return 0;
}
void evaluate_blood_pressure(int systolic_reading, int disastolic,
string & diastolic_evalutation, string & systolic_evaluation)
{
if(systolic_reading <120) // Systolic Interpretation
{
systolic_evaluation = "Optimal";
}
else if(systolic_reading <130)
{
systolic_evaluation = "Normal";
}
else if(systolic_reading <140)
{
systolic_evaluation = "Normal High";
}
else if(systolic_reading <150)
{
systolic_evaluation = "Stage 1 hypertension";
}
else if(systolic_reading <160)
{
systolic_evaluation = "Stage 2 hypertension";
}
else if(systolic_reading <180)
{
systolic_evaluation = "Stage 2 hypertension";
}
if(disastolic < 80) // Diastolic Interpretation
{
diastolic_evalutation = "Optimal";
}
else if(disastolic < 85)
{
diastolic_evalutation = "Normal";
}
else if(disastolic < 90)
{
diastolic_evalutation = "High normal";
}
else if(disastolic < 100)
{
diastolic_evalutation = "Stage 1 hypertension ";
}
else if(disastolic < 110)
{
diastolic_evalutation = "Stage 2 hypertension ";
}
else if(disastolic >= 110)
{
diastolic_evalutation = "Stage 3 hypertension ";
}
}
void evaluate_cholesterol(int hdl_reading, int ldl_reading, string &
hdl_evaluation, string & ldl_evaluation)
{
{
if(hdl_reading < 40) // HDL Interpretation
{
hdl_evaluation = "Too low";
}
else if(hdl_reading >= 40, hdl_reading < 60)
{
hdl_evaluation = "Is okay";
}
else if(hdl_reading >= 60)
{
hdl_evaluation = "Excellent";
}
}
{
if(ldl_reading <100) // LDL Interpretation
{
ldl_evaluation = "Optimal";
}
else if(ldl_reading <= 100, hdl_reading < 130)
{
ldl_evaluation = "Near Optimal";
}
else if(ldl_reading >=130, ldl_reading < 160)
{
ldl_evaluation = "BorderLine High";
}
else if (ldl_reading >= 160, ldl_reading < 190)
{
ldl_evaluation = "High";
}
else if (ldl_reading >= 160, ldl_reading < 190)
{
ldl_evaluation = "Very High";
}
}
}