Why isn't my C++ code working?

+1 Giorgio M · February 26, 2015
Hello everyone, can someone please help me with my code I am trying to run. I am trying to find a solution on why this file is freezes when I run it. 

According to the assignment the program is to

-initialize patientCount to 0
-read first ID and howMany from file
-while not end-of-file
*increment patientCount
*display ID
*use a count-controlled loop to read and sumup this patient’s howMany BP’s
*calculate and display average for patient
*read next ID and howMany from file
-display patientCount





#include
#include
#include
#include
using namespace std;

int main()
{

   //Initialize Required Variables For Program
   int patientCount = 0;
   string id;
   string rHowMany; //String To Read From File
   int howMany = 0;
   int howManyCount = 0;
   int avg = 0;
   int avg2;
   string line;
   int numbre_lines = 0;
   ifstream reader ("data.txt"); //Open The Data File To Be Read From

   do
   {
       reader >> id;
       reader >> howMany;
       cout







So I tried many times but it just gets frozen on the screen.



Also someone tried to help me out to edit it and he told me to do it like this and it still didn't work


#include
#include
#include
#include
using namespace std;



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

    do{
        reader >> id;
        reader >> howMany;
        cout  howMany ){
for(int K=0; K> number;
sum += number;
   } 
    system("pause");
    return 0;
}[/code]


The data.txt file looks exactly like this so far to test it. But it is going to have 20 ID's

4567 4 180 140 170 150
[color=#e0e2e4][font=Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif][/font][/color]
[color=#e0e2e4][font=Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace, serif]5643 2 125 150



Post a Reply

Replies

Oldest  Newest  Rating
+1 Giorgio M · February 26, 2015
Wow this did not come out right. I'm going to repost
+1 Giorgio M · February 26, 2015
Ignore this post. It won't let me delete it because the C++ symbol on the top left is in the way. I am going to repost
  • 1

C++

107,199 followers
About

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

Links
Moderators
Bucky Roberts Administrator