I am currently studying C++ for fun and as a side track am developing a simple text only rpg based loosely on the hobbit mainly for my brother my reasons are that every interview I have ever read/watched has stated that the best thing to do if you want to learn a language is to do it over and over so while I am doing the exercises from several books this is a real world project that I can learn from.
Anyway I digress...
Back to my problem
I have been using swith statements for die rolling and would like to create a class or fuction for aforementioned die roling
and also for coin tossing
to enable the code to be tidier
I have both systems working but would like to be neater
switch(die)
{
case 1:
cout << "\n\nYou rolled a " << die << " and you awake in the Troll mountains!\n\n";
cout << "Lo and behold....\n\n";
cout << "A Troll eats you \n\n";
cout << "Ooops you're dead\n\nBad luck old bean.....";
cout << "\n\n\n\n\t\t\tGAME OVER....\n\n\n\n\n\n";
return 0;
break;
case 2:
cout <<"You roll a "<< die <<" \n\n And things stay the same.";
break;
case 3:
cout << " You roll a "<< die <<"\n\n";
cout <<"you are very lucky to not be burnt alive by a fire,\n that had started in your lounge \n\n";
cout <<" luckily Yaan Bamgee your great friend had put it out for you\n\n";
cout <<"\t\t\tLuck +1\n\n\n\n";
break;
case 4:
cout <<"You rolled a "<< die <<"\n\n And you are poor and start our adventure with no gold\n\n";
break;
case 5:
cout <<"You rolled a " << die <<"\n\n You are rudely awoken by your friend the great wizard Wandalf\n\n";
break;
case 6:
cout <<"You rolled a "<< die <<"\n\n And you are happily awake and make a lovely cup of tea!\n\n";
break;
<code/>
all help greatly accepted please dont be too harsh!
My main aim is to not have to use massive chunks of code all the time and be able to point at this code!
As for your problem, I don't understand what exactly you want to do. Make functions TossCoin() and RollDie() that return random numbers? Put each case in your switch is a separate function?