Jump to content
  • Advertisement
Sign in to follow this  
neshtak

C++ source code help

This topic is 3736 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

Hi. I've been learning C++, and made a little "game menu simulator" to test myself out. Everything worked fine and in order, until enums were added to the code. Firts they were embeded into the switch(), then I decided to make them global by moving enums outside the main(), but still no luck. Though theres less errors now. Can't figure out what's happening... The source code: Download I'm using Dev-C++

Share this post


Link to post
Share on other sites
Advertisement
You are doing cin >> difficulty, but have defined difficulty as an enum.

What you probably meant to do was define an array of strings for your difficulty (and other enums), and a variable for difficulty, and index the array using that variable.

For example:-

char* difficutly_strings[4] = {"novice", "normal", "hard", "hell"};

int difficulty = 0;
...
cin >> difficulty
cout << "You have chosen " << difficulty_strings[difficulty-1] << " difficulty.";


Oh, and note the difficulty-1 is because arrays are 0 based and you are getting a number between 1 and 4.

Share this post


Link to post
Share on other sites
Just three aside points to make really...

1) Enums only define a type and name constants, they don't declare variables - you have to do that like normal:

MyEnum my_enum_variable = whatever;

2) DevC++ is very old. Visual C++ 2008 Express Edition is free, so is Code::Blocks.

3)
Quote:
char* difficutly_strings[4] = {"novice", "normal", "hard", "hell"};
Better to use const:

const char * difficulties[] = { "novice", "normal", "hard", "hell" };

Share this post


Link to post
Share on other sites
I couldn't agree more with the suggestion to use Visual Studio. Admittedly, it is the only IDE I have ever used, but it's pretty great.

Also I think I'd suggesst going with:
const std::string difficutly_strings[4] = {"novice", "normal", "hard", "hell"};

You're using std::string everywhere else and consistency is nice. So far as I know there is no reason to use char* over std::string and if you really need to get at the character array you can always call .c_str() on your string.

Share this post


Link to post
Share on other sites
Sign in to follow this  

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