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>
usingnamespace 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;
}
#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;
}