code skips second cin command

after line 14, the program just ends. It only happens with the exe file and visual studios but not on the cpp.sh website.

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
 #include <iostream>
#include <string>
using namespace std;
int main()
{
	char binary1, binary2, binary3, binary4, binary;
	int total, inch, inches, feet;


	cout << "Enter a four digit binary number: ";
	cin >> binary1 >> binary2 >> binary3 >> binary4;
	binary = (binary1 - '0') * 8 + (binary2 - '0') * 4 + (binary3 - '0') * 2 + (binary4 - '0') * 1;
	total = binary;
	cout << binary1 << binary2 << binary3 << binary4 << " = " << total << " digits";

	cout << "\nEnter inches in 3 digits: ";
	cin >> inch;
	feet = inch / 12;
	inches = inch % 12;
	cout << endl << inch << " inches = " << feet << " feet and " << inches << " inches" << endl;

	system("pause");
	return 0;

}
closed account (48T7M4Gy)
FWIW, Output from VS2015 looks OK to me. Numbers can be input with or without spaces and get same answer.

Enter a four digit binary number: 1 0 1 0
1010 = 10 digits
Enter inches in 3 digits: 123

123 inches = 10 feet and 3 inches
Press any key to continue . . .

Enter a four digit binary number: 1 1 1 1
1111 = 15 digits
Enter inches in 3 digits: 35
Last edited on
Sorry, forgot to mention that i'm using the 2013 version. not sure if that is an issue, but no matter what i get this:

Enter a four digit binary number: 1100
1100 = 12 digits
Press any key to continue . . .
Last edited on
closed account (48T7M4Gy)
try a new line cin.ignore(); between lines 14 and 17. Might fix it
Last edited on
I bet, it started happening after you added lines 16-20 to your program. It looks like you did not compile your program and executing old copy. Rebuild your project completely and try again.
closed account (48T7M4Gy)
LOL - my 'fix' would have worked - woo hoo.
Last edited on
Works just fine for me. If the topic is resolved please mark it as resolved.
Topic archived. No new replies allowed.