Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Question: Need help with code. Need to write program with these specificatio

ID: 3604153 • Letter: C

Question

C++ Question: Need help with code.

Need to write program with these specifications:

Create a program to allow a user to play a modified “craps” games. The rules will be as follows:

1) User starts with $50.00 as their total.

2) Ask the user for their bet (maximum bet is their current total).

3) Throw a pair of dice.

a) If the total value is 7 or 11, the user is an instant winner. The user has the amount bet added back into their total. Ask the user if they wish to play again and if so they start at step two above.

b) If the total value is 2, 3, or 12, the user is an instant loser. The user has the amount bet deducted from their total. Ask the user if they wish to play again and if so they start at step two above.

c) If the total is anything else, remember this total as the “point” and roll again.

i) If the new total is equal to the “point”, the user wins and the process is the same as winning in (a) above

ii) If the new total is a 7, the user loses. And the process is the same as losing in (b) above.

iii) If the new total is anything else the user must roll again and again try to match the “point” of the first roll.

Explanation / Answer

The code in C++


#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int diceThrow()
{
   srand(time(NULL));
   return rand() % 6;
}

int main()
{
   int total = 50, betAmount = 0, dice = 0, point;

   char c;


   askBet:
   cout << "Enter the bet amount : " << endl;
   cin >> betAmount;

   if (betAmount > total)
   {
       cout << "Bet amount is greater than total, enter correct bet amount. Total = " << total << endl;
       goto askBet;
   }

   dice = 0;
   for (size_t i = 0; i < 2; i++)
   {
       dice += diceThrow();
   }

   if (dice == 7 || dice == 11)
   {
       total = total + betAmount;

       cout << "You won.New total = " << total << endl;

       cout << "Do you want to play again ?(Y/N)" << endl;
       cin >> c;

       if (c == 'y' || c == 'Y')
       {
           goto askBet;
       }

       else
       {
           return 0;
       }
   }

   if (dice == 2 || dice == 3 || dice == 12)
   {
       total = total - betAmount;

       cout << "You lost.New total = " << total << endl;

       cout << "Do you want to play again ?(Y/N)" << endl;
       cin >> c;

       if (c == 'y' || c == 'Y')
       {
           goto askBet;
       }

       else
       {
           return 0;
       }
   }

   cout << "match the previous bet, rolling again." << endl;
   point = dice;
   matchPoint:
   dice = 0;
   for (size_t i = 0; i < 2; i++)
   {
       dice += diceThrow();
   }

   if (dice == point)
   {
       total = total + betAmount;

       cout << "You won.New total = " << total << endl;

       cout << "Do you want to play again ?(Y/N)" << endl;
       cin >> c;

       if (c == 'y' || c == 'Y')
       {
           goto askBet;
       }

       else
       {
           return 0;
       }
   }

   if (dice == 7 )
   {
       total = total - betAmount;

       cout << "You lost.New total = " << total << endl;

       cout << "Do you want to play again ?(Y/N)" << endl;
       cin >> c;

       if (c == 'y' || c == 'Y')
       {
           goto askBet;
       }

       else
       {
           return 0;
       }
   }

   cout << "The new roll did not matched the point. Rolling again. " << endl;
   goto matchPoint;

   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote