? with Do While

In my do...while loop I have this below. when I do that and the loop repeats, it ignores one of my variables.

I ask them to enter their name and it just puts the cout and skips the cin. It works fine the first instance though.

SO it doesn't let me type in my name in plain english after the second instance and so on.

1
2
3
4
string your_name;

cout <<"What is your name?" << endl;
   getline(cin,your_name);

You need to post more code.
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
# include <time.h>
using namespace std
;int main()
{int maximum;
int minimum;
int random_number;
int req_subtraction;
int current_total;
int total;

do
{
string your_name;

cout <<"What is your name?" << endl;
   getline(cin,your_name);

cout << "Total Limit?" << endl;   //can't go over this
cin >> total;
 
cout << "Max you can add?" << endl;
cin >> maximum;
 
cout << "Minimum you can add?" << endl;
cin >> minimum; 
 
cout << "Required Subtraction?" << endl;
cin >> req_subtraction;
 
 srand(time(0));  //seed the random number
 
int high=maximum;
int low=minimum;
 
do
{random_number = rand () % (high - low + 1) + low;//random number between max and min
 
cout << "Random Number is " << random_number << endl;
current_total += random_number - req_subtraction;    
if(current_total < 0)   //make so negatives equal out to zero    
{    current_total = 0;    }
 cout << "The current total is " << current_total << endl;
}
while (current_total < total); 
 cout << "Would you like to try again? (yes/no)\n";
    cin >> yes_no; 
} while (yes_no == "yes");

cout << "Goodbye.\n";
system("pause");
return 0;
}
try just:
cin>>your_name , instead of getline operation.
Topic archived. No new replies allowed.