getline function in simple program

I am writing a simple program to test a looping sequence and am using a string variable along with numerical inputs. I initially used just a single word "name" as the string variable and the cin >> name;
function and it worked fine.

I then wanted to try it using first and last names and thought the getline function would serve me in that role. The program doesn't do anything after the inputs are typed in.

The program asks for a user name and a list of numerical inputs, it then is supposed to output the name along with the average and sum of all the numbers.

If anyone could tell me what is wrong with what I have, I would appreciate it. The only change I made to the program was to substitute the "getline" function for the the "cin" function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
getline(cin, name);
     while(cin){
                sum = 0;
                count = 0;
                cin >> trans;
                while (trans != SENTINEL){
                sum = sum + trans;
                count ++;
                cin >> trans;
                }
     if (count != 0)
     average = sum / count;
     else 
     average = 0;
     
     cout << name << "Average trans: " << average << " and total trans: " << sum << endl;
     
     getline(cin, name);
Topic archived. No new replies allowed.