I need them helps... again!

Started by
2 comments, last by FredOrJoeBloggs 11 years, 8 months ago
#include <iostream>
using namespace std;
int main()
{
char a;
char b = "y";
char c = "n";

cout << "Am I a troll? (n/y)";
cin >> a;
if(a == b){
cout << "?????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????" << endl;
cout << "???????????????????????????????";
}
if(a == c){
cout << "D'aw";
}else{
cout << "Am I a troll? (n/y)";
cin >> a;
}

return 0;
}


I need help, what this program is meant to do is to ask if I'am a troll and if the answer == "y" then it will print out the ASCII troll face(:D) and if the answer == "n" then it will print "D'aw" and if answer is anything else then it will ask again (I'm 99% sure that the else par I made is completly wrong so yeah, I'am a newbie in C++) BUT I get an error in line 8 and 9 or the lines with "char b = 'y' " and "char c = 'n' " it says "invalid conversion from 'const char*' to 'char'"
Advertisement
You confused strings with characters. They are not the same thing.
char b = "y"; // put addres of first element of array{'y', 0} in variable b. b is not a pointer thus invalid assignment.
char c = "n"; // same

char d = 'y'; // correct
As a side note, you can compare char literals directly inside if conditional evaluations. char is not magic, it's 8 bit storage which, when fetched to cout is used to look up a glyph to display. What the quoting does is to tell the compiler to look inside for a char/escape sequence and encode it as appropriate storage.
Similarly, double-quoting informs the compiler to build a string.
They are two very different things. Be careful in particular that you cannot trivially compare raw c-strings (usage of [font=courier new,courier,monospace]std::string[/font] is encouraged).

Previously "Krohm"

ty
Kripis,

This might help you http://www.tutorialspoint.com/cplusplus/index.htm

This topic is closed to new replies.

Advertisement