cin.get problem

The second cin.get in my program is not taking in information. By that I mean, the program skips it, and doesn't ask for input. It just goes straight to the cout line. Everything else in it is working fine.

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
#include "stdafx.h"

using namespace std;

char Choice[9];

char Name[11];

int _tmain(int argc, _TCHAR* argv[])
{
	system("Color 0a");

	cout << "  H H EEE RRR OOO" << endl;
	cout << "  H H E   R R O O" << endl;
	cout << "  HHH EEE RRR O O" << endl;
	cout << "  H H E   RR  O O" << endl;
	cout << "  H H EEE R R OOO" << endl << endl;
	cout << "QQQ U U EEE SSS TTT" << endl;
	cout << "Q Q U U E   S    T " << endl;
	cout << "Q Q U U EEE SSS  T " << endl;
	cout << "QQQ U U E     S  T " << endl;
	cout << "  Q UUU EEE SSS  T " << endl;

	system("Pause >nul");
	system("CLS");

	cout << "+----------+" << endl;
	cout << "|   Main   |" << endl;
	cout << "+----------+" << endl;
	cout << "| New Game |" << endl;
	cout << "|   Load   |" << endl;
	cout << "+----------+" << endl << endl;

	cin.get(Choice, 9);

	if(strcmp(Choice, "New Game") == 0)
	{
		goto New_Game;
	}

	system("Pause");

New_Game:

	system("CLS");

	cout << "What is your name? (12 char max)" << endl <<endl;
	
	cin.get(Name, 11);

	cout << "Welcome " << Name << "!" << endl;

	system("Pause >nul");

	return 0;
}
The console is a terrible medium for a game.

Do yourself a favor and stop now. Pick up a game lib like SFML, and restart this project in a sane way.

Other relevent reading:
http://cplusplus.com/forum/general/27463/#msg146963
http://cplusplus.com/forum/general/27463/#msg147120
Last edited on
I was planning to redo everything in DirectX. But, you know... Laziness....
Honestly, I'm not a fan of DirectX. Yeah it's quick and powerful but it's pretty obfuscated, and it's certainly not beginner friendly.

Really, though, try SFML. It's very beginner friendly. It also uses OpenGL under the hood so it has the perk of being extremely fast and crossplatform.

http://www.sfml-dev.org
to answer your question, it's probably the system(pause) getting input from keyboard and the cin.get a couple lines below taking that input as it's own.
Topic archived. No new replies allowed.