Jump to content
  • Advertisement

Archived

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

RaistlinMajere

help!!

This topic is 5387 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Guest Anonymous Poster
You haven''t given a value to your chars

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Your archer etc name is wrong, you need only ONE character in the

if(clas == ''Archer'')

area

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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!