Closing everytime I input a name/letter

Nov 26, 2013 at 5:47pm
so I'm busy making a simple text adventure game and right now i'm doing the
intro bit but everytime you insert a name my program just closes
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
  #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
	int awnser;
	int name;



	cout << "   Pugs in the world   " << endl;
	cout << "  By ShinyPug Company         " << endl;
	cout << "" << endl;
	cout << "" << endl;
	cout << "" << endl;
	cout << "" << endl;

	cout << "Owner: I'm going to call you..." << endl;
	cout << "Please enter a name." << endl;
	cin >> name;
	cout << "Owner: I'm going to call you " << name <<  endl;

	
	cin.ignore();
	cin.ignore();
	return 0;

}
Nov 26, 2013 at 5:53pm
Nov 26, 2013 at 5:55pm
I already know that but cin.ignore() normally works.
Nov 26, 2013 at 6:28pm
You have declared variable "name" as type int, you may want to change that to string. [you will need #include <stream>]

If you want user to be able to enter first and last name then use getline () instead of cin.

You also have typo in one of your variable names. It should be "answer" not "awnser".
Nov 26, 2013 at 10:52pm
RabMac String is under #include <string> not stream.
Nov 27, 2013 at 11:53am
Well thanks for the info on the string part

but its still closing!
Nov 27, 2013 at 12:57pm
Use cin.get()
Nov 27, 2013 at 1:15pm
Yeah I meant <string> gibilit ;)

Instead of using cin use getline ()
Nov 27, 2013 at 1:48pm
@RabMac

getline ()

is not working

"getline is undefined"
Nov 27, 2013 at 4:43pm
std::getline( std::cin , string_goes_here );
Nov 27, 2013 at 5:29pm
that did not work but I figured something out!

when it closing I can only see a not amy
so I typed in a and that worked

but when I type in a full name it just closes.
Topic archived. No new replies allowed.