With full credit, this program will add 2 points to your overall final grade. As
ID: 3690281 • Letter: W
Question
With full credit, this program will add 2 points to your overall final grade. As always, this program should be completed individually. Write a program that uses methods and simulates the rolling of three separate 6 sided dice. The user should start with 10 dollars in a bank. Before each roll of the three die, the user can bet in whole dollars how much of the amount in the bank to risk. The user should not be allowed to risk more than is currently in the bank. On each roll, each separate die should randomly roll one of the numbers between 1 and 6. If any two numbers on the three die is the same the user makes 5 times the bet. If all three numbers are the same on all three die, the user makes 20 times the bet. Allow the user to quit at any time. Keep track of how many rolls before the entire bank is gone. The final date/time to submit this assignment is Friday, April 29th at midnight.Explanation / Answer
#include <iostream>
#include <cstdlib> /* srand, rand */
#include <ctime> // time
using namespace std;
int main() {
float bank = 10,bet;
int die[3];
int guess[3];
int count,opt,nor=0;
while(1){
while(1){
cout<<"Enter the amount to bet :";
cin>>bet;
if(bet > bank)
cout<<"You cannot bet an amount greater than your balance"<<endl;
else
break;
}
for(int i =0;i<3;i++)
die[i]= (rand() % 6) + 1;
nor++;
cout<<"Enter your 3 choices";
cin>>guess[0]>>guess[1]>>guess[2];
for(int i=0;i<3;i++){
count = 0;
for(int j=0;j<3;j++)
if(guess[i] == die[j] && guess[i]!=0 && die[j] !=0){
guess[i] = 0;
die[j] = 0;
count = count+1;
break;
}
}
if(count == 3){
bank = bank + 20 * bet;
cout<<"All the guesses were right";
}
else if (count == 2){
bank = bank + 5 * bet;
cout<<"Two of the three guesses were right";
}
else{
bank = bank - bet;
cout<<"Less than two guesses were right";
}
if(bank == 0){
cout<<"You have exhausted all your money";
break;
}
cout<<"Do you want to continue: Press 1 to continue";
cin>> opt;
if(opt != 1)
break;
}
cout<<" Thanks for palying. Total number of rolls = "<<nor;
cout<<" Total balance in the bank = "<<bank;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.