Archived

This topic is now archived and is closed to further replies.

RaistlinMajere

help!!

Recommended Posts

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:
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???!!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Instead of char, use string. For example:


#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.

Share this post


Link to post
Share on other sites