The program jumps one step ahead

I have a program that calculates the something bla bla bla and I need the user to input some numbers from the keyboard and when I select the function that does the reading I get on the screen something like:

"[...text...] please make your selection: (I press 1) Please insert your first number: incorrect entry, try again! Please insert your first number:" and then it allows me to input a number. I need to get rid of that first "Please insert number" but I do not know how to do it. I think it has something to do with flushing the buffer, but I am new to Cpp and I do not know how to proceed.



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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
void className::read() {
	int i, ans1;
	for (i = 1; i <= 6; i++) {
		bool fQuit = false;
		switch (i) {
		case 1:
			while (!fQuit)
			{
				cout << "Insert the first number: " << ends;
				string temp;
				getline(cin, temp);
				stringstream stream(temp);
				double int_choice;
				if (!(stream >> int_choice) || stream.peek() != char_traits<double>::eof())
				{
					cout << "Incorrect entry, try again\n";
				}
				else
				{
					S = stod(temp);
					fQuit = true;
					break;
				}
			}
			break;

		case 2:
			while (!fQuit)
			{
				cout << "Insert the second number: " << ends;
				string temp;
				getline(cin, temp);
				stringstream stream(temp);
				double int_choice;
				if (!(stream >> int_choice) || stream.peek() != char_traits<double>::eof())
				{
					cout << "Incorrect entry, try again\n";
				}
				else
				{
					K = stod(temp);
					fQuit = true;
					break;
				}
			}
			break;

		case 3:
			while (!fQuit)
			{
				cout << "Insert the third number " << ends;
				string temp;
				getline(cin, temp);
				stringstream stream(temp);
				double int_choice;
				if (!(stream >> int_choice) || stream.peek() != char_traits<double>::eof())
				{
					cout << "Incorrect entry, try again\n";
				}
				else
				{
					T = stod(temp) / 12;
					fQuit = true;
					break;
				}
			}
			break;

		case 4:
			while (!fQuit)
			{
				cout << "Insert the fourth number " << ends;
				string temp;
				getline(cin, temp);
				stringstream stream(temp);
				double int_choice;
				if (!(stream >> int_choice) || stream.peek() != char_traits<double>::eof())
				{
					cout << "Incorrect entry, try again\n";
				}
				else
				{
					sig = stod(temp);
					if (sig > 1) {
						sig = sig / 100;
					}
					fQuit = true;
					break;
				}
			}
			break;

		case 5:
			while (!fQuit)
			{
				cout << "Insert the fifth number" << ends;
				string temp;
				getline(cin, temp);
				stringstream stream(temp);
				double int_choice;
				if (!(stream >> int_choice) || stream.peek() != char_traits<double>::eof())
				{
					cout << "Incorrect entry, try again\n";
				}
				else
				{
					r = stod(temp);
					if (r > 1) {
						r = r / 100;
					}
					fQuit = true;
					break;
				}
			}
			break;

		default:
			break;
		}
	}
}
////////////////////////////////////////////////////////////////////////////////
int main() {
	int ans;
	//string iInp;
	header();
label1:
	menu();
	ans = exhan();
	className init;
	init.read();
	switch (ans)
	{
	case 1: 
	{
		className obj0;
		//obj0.read();
		obj0.N();
		//obj0.select();
		cout << "text: " << obj0.result() << endl;
		system("Pause");
		goto label1;
	}
[...]
defaul:
break;
*there are more cases but they are very similar to the first one.
	system("pause");
	return 0;
}
You only want it to look like:

please insert first number
< moo!
incorrect, try again
<no!
incorrect, try again
123
...

then take the cout above the while loop, like this:


cout << "Insert the first number: " << ends; //put it here
while (!fQuit)
{
// remove this one cout << "Insert the first number: " << ends;
string temp;
getline(cin, temp);
etc...


Topic archived. No new replies allowed.