I really need help with this code. I'm going crazy

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


Here is my code so far

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
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
#include <conio.h>
#include <fstream>
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 << "The Patient ID Is: " << id << endl;
        cout << "The Number Of Blood Pressure Record This Patient Has Is: " << howMany << endl;
        do
        {
            reader >> avg;
            avg = avg + avg;
        }
        while (reader != "\n");
        cin.clear();
        avg = avg / howMany;
        cout << "The Patient Average BP Reading Is: " << avg;
    }
    while (!EOF);
    return 0;
}



The data.txt file looks exactly like this
1
2
4567 4 180 140 170 150
5643 2 125 150



EDIT:

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

Also I am going to try to have a minimum of 20 patients ID's
If anyone can help me out I greatly appericate that.
Last edited on
I'm not sure if you can use !EOF instead of !reader.eof()

My initial suggestions are to change that, and to add the same eof check into your inner while (the reader != "\n" loop)
@ultifinitus
Thanks so much. But now the code isn't showing all the information, it is only showing 1 of the Patient ID's. But I am trying to show a minimum of 20 but my data file has only 2 just for testing out. If you could help me that'll be great. Thanks again man that change really help.
The rest is logic, that is what programming is all about my friend.
@ultifinitus

You are correct. Thank you so much for the help. That's probably the main thing I needed help on.
Topic archived. No new replies allowed.