Im so lost. Can someone please help. Im suppose to write a program that has a menu with the following options; a) Play Dice game, b) Display Odd numbers, c) Quit. The menu displays until the user chooses option c which terminates the program. If the user selects option a) then prompt the user to roll the dice. The user starts with 10 points. If the user rolls a 5 then he/she loses the game and the program terminates. If the user rolls 1 or 3 he/she wins 5 points. If the user rolls 2, 4, or 6 he/she loses 2 points. After each roll the program displays the number the user rolled, the points won or lost, and the user’s total score. If the user’s score is <= 0 he/loses and the program terminates. If the user’s score is >=25 then the game ends informing the user that he/she won. If the user decides not to roll the dice the game out puts the user’s score and returns to the menu. If the user selects option b) then just display, “Odd number game not yet completed. Returning to menu”.
while (choice != 'q')
{
cout<<"\n\nMenu";
cout<<"\na) Play Dice Game If";
cout<<"\nb) Play Dice game switch";
cout<<"\nc) Quit";
cout<<"\nD) Please enter a selection";
cin>>choice;
switch(choice)
{
case 'a':
case 'A':
//only one of these functions
// I place both here to show here you would place your code
playDice_v2();
break;
case 'b':
case 'B':
playDice_v1();
break;
case 'c':
case 'C':
choice = 'q';
break;
default:
cout<<"\n\nSorry, incorrect selection. Please try again.";
}//end of switch
}//end of while
}
void playDice_v1()
{
int roll = 0, account = 10;
char play= 'y';
cout << "Your account is; " <<account <<endl;
srand(time(0));
while (play == 'y')
{
roll = rand() % 6 + 1;
//keeping score
switch (roll)
{
case 2:
case 4:
case 6:
account = account +5;
cout <<"you rolled" <<roll
<<"' You won 5 points. Your account is now"
<<account<<". \n";
break;
case 3:
case 5:
account = account -2;
cout <<"you rolled" <<roll
<<"' You lost 2 points. Your account is now"
<<account<<". \n";
break;
default:
cout <<"you rolled a one. Sorry, you lose.\n";
play = 'n';
}//end of switch
//checks to terminate program
if (account <=0 || account >=25)
play = 'n';
if (play != 'n')
{
cout<<"You rolled a one. Sorry, you lose.\n";
play = 'n';
}
if (play == 'n')
cout<<"\nGame ending. bye\n";
}//end of while
}//end of void
void playDice_v2()
{
int roll = 0, account = 10;
char (play = 'y')
cout << "Your account is : " << account << endl;
srand(time(0));
while (play == 'y')
{
roll = rand() % 6 + 1;
//keepig score
if (roll == 2 || roll == 4 || roll == 6) {
account = account + 5;
cout << "you rolled" << roll
<< ", You won 5 points. Your account is now "
<< account << ". \n";
}
else if (roll == 3 || roll == 5) {
account = account - 2;
cout << "you rolled" << roll
<< ", You lost 2 points. Your account is now "
<< account << ". \n";
} else {
cout << "You rolled a one. Sory, you lose. \n";
play = "n";
}
//checks to terminate program
if (account<=0 || account >=25)
play = 'n';
if (play !='n')
{
cout <<"Would you like to play again? (y/n) :";
cin>>play;
}
if (play -- 'n')
cout<<"\nGamr ending. bye!\n";
First of all "newflyyera" please format your code and make sure it is in code blocks so that it is inviting and easy to read ([code]).
There seems to be several problems with your code:
1) In the function playDice_v2() you are assigning 'play' a value the wrong way. Get rid of the braces and add a semicolon at the end of the statement.
2) Again in playDice_v2(), inside the last else statement with in the while loop, you are trying to assign the char variable play a string (play = "n").
3) Again in the same loop, did you notice that you are using the operator -- to check if play equals 'n'?
4) Finally, as you mentioned in your question (honestly, I don't know what you are asking for), you must add cout << account << endl; in you code so that the player's score will be displayed before returning to your menu.
I hope this helps. Again, please try putting your code in the code blocks so that it can be easily understood.