The introduction of wagering also means that some code will

The introduction of wagering also means that some code will have to be added to int main() to keep track of the user\'s balance (or bank). Every instance where the user can win the game will require the addition of code to increase the user\'s balance by the amount that they wagered. Every instance where the user can lose the game will require the addition of code to decrease the user\'s balance by the amount that was wagered. The user will start with a balance of $100.00 and the minimum amount that they can wager is $5.00. Note: this program will not be handling the true odds from the game. The user will simply win or lose whatever money they wager. Never more and never less.

Once the game is over, display the user\'s final balance amount.

The Functions

For this program, there are two required functions:

int rollDice()

This function will handle the rolling of the two die, calculating the sum of the dice, displaying the dice and the sum, and then returning the calculated sum.

The function takes no argument. It returns an integer value that represents the sum of the dice.

As with program 4, the value for each die must be between 1 and 6, inclusive.

double getWager( double balanceAmount )

This function will get and return a desired (valid) wager amount from the user.

The function takes one argument: a double value that represents the user\'s current balance. It returns a double value that represents the amount of the user\'s wager.

The code for this function should prompt the user for the amount that he/she would like to wager. The prompt should include the user\'s current balance and the amount of the minimum wager ($5.00). The amount that is entered by the user must be a valid value, meaning that it must be between the minimum wager amount and the user\'s balance, inclusive. If the user enters an invalid wager amount, an error message should be displayed and the user should be given a chance to re-enter the wager amount. This should continue until the user enters a valid wager amount. Once a valid amount has been entered, it should be returned to the function that called the getWager function.

Note: the error message should include the invalid wager amount.

Solution

#include<iostream>
using namespace std;

int rollSum;
//Roll Dice
int rollDice()
{
int d1, d2;
cout<<\"The value for each die must be between 1 and 6\";
do
{
cout<<\"\ Enter Dice 1 value \";
cin>>d1;
//Validates dice between 1 and 6
if(d1 >= 1 && d1 <= 6)
{
break;
}
else
{
cout<<\"\ Error: Invalid value [The value for each die must be between 1 and 6]\";
continue;
}
}while(1);

do
{
cout<<\"\ Enter Dice 2 value \";
cin>>d2;
//Validates dice between 1 and 6
if(d2 >= 1 && d2 <= 6)
{
break;
}
else
{
cout<<\"\ Error: Invalid value [The value for each die must be between 1 and 6]\";
continue;
}
}while(1);
//Calculates sum
rollSum = d1 + d2;
return rollSum;
}

//Wager Operation
double getWager( double balanceAmount )
{
double weiger;
do
{
cout<<\"\ Enter the amount that he/she would like to wager.\";
cin>>weiger;
//Validates wager value to minimum 5
if(weiger < 5.00)
{
cout<<\"\ Minimum amount for the wager is $5.00.\";
continue;
}
//Validates wager value to balance amount
else if(weiger > balanceAmount)
{
cout<<\"\ More than the Balance Amount\";
continue;
}
//Checks for Win or Loss
else if(rollSum % 2 == 0)
{
balanceAmount = balanceAmount + weiger;
cout<<\"\ Win: Balance = \";
return balanceAmount;
}
else
{
balanceAmount = balanceAmount - weiger;
cout<<\"\ Loose: Balance = \";
return balanceAmount;
}
}while(1);
}

int main()
{
double startBalance = 100.00;
cout<<\"\ Dice sum = \"<<rollDice();
startBalance = getWager(startBalance);
cout<<startBalance;
}

Output 1:

The value for each die must be between 1 and 6
Enter Dice 1 value 9

Error: Invalid value [The value for each die must be between 1 and 6]
Enter Dice 1 value 5

Enter Dice 2 value 8

Error: Invalid value [The value for each die must be between 1 and 6]
Enter Dice 2 value 6

Dice sum = 11
Enter the amount that he/she would like to wager.4

Minimum amount for the wager is $5.00.
Enter the amount that he/she would like to wager.110

More than the Balance Amount
Enter the amount that he/she would like to wager.20

Loose: Balance = 80

Output 2:

The value for each die must be between 1 and 6
Enter Dice 1 value 5

Enter Dice 2 value 7

Error: Invalid value [The value for each die must be between 1 and 6]
Enter Dice 2 value 5

Dice sum = 10
Enter the amount that he/she would like to wager.50

Win: Balance = 150

The introduction of wagering also means that some code will have to be added to int main() to keep track of the user\'s balance (or bank). Every instance where
The introduction of wagering also means that some code will have to be added to int main() to keep track of the user\'s balance (or bank). Every instance where
The introduction of wagering also means that some code will have to be added to int main() to keep track of the user\'s balance (or bank). Every instance where

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site