do while loop skipping a step

in my do while loop, i have the user enter a response with y or n to continue or end the program. during the loop, if i enter y or Y, it would skip asking the first number, line 24 and go to asking the second number, line 36. does anyone know why it skipping a step and go to the next step?

EDIT: code removed and problem solved so i did a new problem thats like my old one, where coder777 reply would solve it =D
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string num1, num2;
	char reply;

	do
	{
		cout << "Enter a number: ";
		getline(cin,num1);
		cout << "Enter another number: ";
		getline(cin,num2);
		cout << "Their sum is " << (num1 + num2) << endl;
		cout << "Do you want to do this again? ";
		cin >> reply; 
	}
	while (reply == 'y' || reply ==  'Y');
	return 0;
}

Last edited on
Skipping that line happens when mixing 'getline()' and 'cin >> ...;' since 'cin >> ...;' leaves the new line in the stream which 'getline()' takes and returns immediately.

When it comes to cin you don't need 'getline()' since the console always waits for 'enter' to return.
There a particular reason why you removed your code, TC?
Edit:

I put the original post here, as it had been deleted, and I now remove it again at request of dznguy who does not want his homework assistance in full view of the world. :)
Last edited on
since this is a hw assignment which i wrote from scratch and if anyone who happen to stumble upon this code in the future would just copy it and does nothing else =x. so for their benefit, i just removed it
Last edited on
Topic archived. No new replies allowed.