C++ problems

I have a problem, When i run my Program, it tells me to input a name which is what is't meant to do, but when it says are you sure it's (name), it only shows the first letter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using namespace std;
int main ()
{
	char yeh, yes, ya, yep;
	char yess;
	char Name;
	char Answer;
    yess == yeh, yes, ya, yep;
cout << "What is your name?\n";
cin >> Name;
cout << "Are you sure it is " << Name << "?";
cin >> Answer;
if (cin >> yess)
	cout << "\nGood!";
else
cout << "\nSo,";
system("PAUSE");
return 0;
}
there are several problems:
0) variables must be declared with the first letter lowercase letter;

1) line 8 does not fit as you declared values ​​'yess', but also because I believe that in order to do what you want, 'yess' must be of type string;

2) line 13, if I understand what you wanted to do, you should write:
if (answer == yess) ...

but precisely, what did you do?
closed account (ypfz3TCk)
I think you should use std::string rather than char.
eg
1
2
3
4
string name;
cout << "What is your name?";
cin >> name;
cout << "Are you sure it is " << name << "?" << std::endl;


You are using type char as the variable which for your program will store 1 character only. If you want to get input of a name - a string of characters combined - you need to use a string type as the storage variable.
hth
0) variables must be declared with the first letter lowercase letter;


Nonsense.


0) variables must be declared with the first letter lowercase letter;


Nonsense.



more precise:
is a convention.
he will have an issue if he types in a first and last name so:
getline(cin,"name of your string")
will get whatever you type in for that line of strings

otherwise if he types in Mr. Anderson it will only output Mr.
Last edited on
Topic archived. No new replies allowed.