int main()
{
char clas;
char name;
std::cout<<" Select your class:Archer, Warrior\n";
std::cin>>clas;
if(clas == ''Archer'')
{
std::cout<<"Your an archer!\n";
}
if(clas ==''Warrior'')
{
std::cout<<"Your a warrior \n";
}
else
{
std::cout<<"Thats not a class:Quiting!\n";
}
return 0;
}
whats wrong???!!
help!!
ok i get these two errors from this code:
C:\Documents and Settings\Tyler\rpg\rpg1.cpp(44) : error C2015: too many characters in constant
C:\Documents and Settings\Tyler\rpg\rpg1.cpp(48) : error C2015: too many characters in constant
heres the code:
Your archer etc name is wrong, you need only ONE character in the
if(clas == ''Archer'')
area
if(clas == ''Archer'')
area
clas is a char, a single character, and hence
clas == ''anything more than one letter''
will not work, only
clas == ''X'';
You''ll need to work with char strings entirely, or ask the user to type A for Archer etc.
Wizza Wuzza?
clas == ''anything more than one letter''
will not work, only
clas == ''X'';
You''ll need to work with char strings entirely, or ask the user to type A for Archer etc.
Wizza Wuzza?
Instead of char, use string. For example:
Note the following:
#include <iostream>#include <string>using namespace std;int main(){ string clas; string name; cout<<" Select your class:Archer, Warrior" << endl; cin>>clas; if(clas == "Archer") { cout<<"You''re an archer!" << endl; } if(clas =="Warrior") { cout<<"You''re a warrior" << endl; } else { cout<<"That''s not a class:Quiting!" << endl; } return 0;}
Note the following:
- "Your" indicates possession, while "you''re" is a contraction of "you are." (Sorry for the pedanticism, but these things are important.)
- The proper contraction of "that is" is "that''s."
- String literals are always in double-quotes. Character literals are in single-quotes.
- Use endl instead of \n. While they both add a new-line to the string, endl also flushes the stream, which is often when you want. If the stream doesn''t get flushed, you won''t see the output you expect if your program crashes.
Or you could use an array of char, but strings would work better.
Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|
Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement