Logic of code not working

+1 Giorgio M · February 26, 2015
Okay I got the code working fine now but the logic isn't there.

What is happening is I have a .txt file in my project like this.

4567 4 180 140 170 150
4693 1 119
4690 5 200 120 135 136
4693 2 149 133
4783 3 133 123 140
4824 3 130 155 120
4833 2 119 186


1st column is Patient ID
2nd column is How Many Tests the patient had
3rd column and beyond is all the blood pressure readings.


How do I calculate the average for the data? The issue I came across was how do I pull those blood pressure readings out of the text file and add them all up to divide them by my variable howMany. Code is working fine I just need the average. Thanks

-Giorgio



#include
#include
#include
using namespace std;

int main(){
//Initialize Required Variables For Program
int patientCount = 0;
string id;
int avg = 0;
int howMany = 0;
ifstream reader ("data.txt"); //Open The Data File To Be Read From

while( reader >> id && reader >> howMany ){ //as long as you can read another pacient data
int sum = 0; //sum accumulates the pressure readings per pacient
cout

Post a Reply

Replies

Oldest  Newest  Rating
+1 Giorgio M · February 26, 2015
http://pastebin.com/GB8P71cs



It didn't post correctly again. It's on pastebin
  • 1

C++

106,979 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator