Cannot input when executed.

Hi,
I am a complete novice with C++, I've been trying to teach myself for the past few days. I have some experience in types of programming (BASIC and HTML/CSS) and I am very computer literate. I have written this code which is really simple but for some reason, when executed, I can only input on the "name" variable. Everything else is just executed and the DOS window closes. I've stepped through the code and can't find why. I might have missed something or maybe I just can't see the wood for the trees! Using Visual Studio Express 2008.
Any help would be greatly appreciated...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main()
{
	cout << "Please enter your name: ";
	char name;
	cin >> name;
	cout << "Please enter your year of birth: ";
	char year;
	cin >> year;
	cout << "So your name is: " << name << " and you were born in: " << year;
	char response;
	cin >> response;
	return 0;
}
hey,

you have to use std::string if you will read a whole word. char is only for one character!

here your code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string> // std::string

using std::cout ;
using std::cin ;
using std::string ;
using std::getline ;
int main()
{
	cout << "Please enter your name: ";
	string name;
	getline (cin, name); // getline reads a whole line with whitespaces. cin reads only a word until it reaches a whitespace
	cout << "Please enter your year of birth: ";
	string year;
	cin >> year ;
	cout << "So your name is: " << name << " and you were born in: " << year;
	char response;
	cin >> response;
	return 0;
}



bye and have fun (:
Last edited on
Oh right. I've not read far enough into tutorial. Running before I can walk me thinks!
Thanks for the help... :0)
Topic archived. No new replies allowed.