Write a C program that simulates a dice game Prompt the user

Write a C++ program that simulates a dice game. Prompt the user for a betting balance. Then start the game. Prompt the player for a bet amount. The amount has to be less or equal to the bet balance. The player cannot bet with a $0 balance. If the player rolls two dice that sum anywhere between 2 and 6 the player wins the bet, and the bet amount is added to the betting balance. If the player rolls a total between 7 and 12 the player loses, and the bet amount is subtracted from the betting balance. After each roll the player is asked if they want to continue playing. If they decide to stop display the ending balance with a friendly message. If the balance is greater then what they started with congratulate them on winning. If the amount is less than what they started with display a message that wishes them better luck next time. You are required to use a method to roll a six sided. You are also required to write a method that accepts a valid bet from the user. If the use enters an invalid bet the method will display a message letting the user know, and prompt again for a valid bet. If the user enters three invalid bets in a row the user is asked to leave the casino, and the game ends. The final balance should still be displayed.

Solution

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

int roll(){
   return rand() % 6 + 1;
}

int main(){
   double balance;
   srand(time(0));
   cout << \"Please enter your starting balance int whole dollars: \";
   cin >> balance;
   cout << \"Your beginning balance is $\" << balance << \", good luck!!\ \";

   double bet;
   while(true){
       cout << \"\ Enter a valid bet: \";
       cin >> bet;
       if(bet > balance){
           cout << \"That is more than your balance\ \";
           continue;
       }
       int a = roll();
       int b = roll();
       int sum = a + b;
       cout << \"Your roll is \" << a << \" and \" << b << \" for a \" << sum << \", \";
       if(sum >= 2 && sum <= 6){
           cout << \"you win\ \";
           balance += bet;
       }
       else{          
           cout << \"you lose\ \";
           balance -= bet;
       }
       cout << \"Your balance is $\" << balance << \"\ \";
       char again;
       cout << \"Do you want to continue(Y/N)?\ \";
       cin >> again;
       if(again == \'Y\') continue;
       else break;
   }
   cout << \"You have $\" << balance << \"\ \";
   cout << \"Better luck next time! have a wonderful evening!\ \";
}

 Write a C++ program that simulates a dice game. Prompt the user for a betting balance. Then start the game. Prompt the player for a bet amount. The amount has

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site