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

Hello, I am trying to recreate a simple game called \'craps\' on the computer. I

ID: 3563388 • Letter: H

Question

Hello, I am trying to recreate a simple game called 'craps' on the computer. I am having trouble with the first part of the program, where the player bets for himself. Here are the rules for betting for yourself

*If the first roll of the dice results ina 7 or 11, then the player automatically wins

*If the first roll results in a 2, 3, or 12 then the player immediately looses

*if the first roll results with any other number (1,4,5,6,8,9,10), that number becomes the player's "point". At this point in the game, the player has a second chance to increase his bet. He cannot bet more than what he has. After he adjusts the bet, the player's goal is to now roll that "point" number again before rolling a 7. If he does, he wins. If he rolls a 7, he looses the bet.

*when the game ends (he looses or wins the bet), the player has the choice to play the game again, if he chooses yes it will reset him with $100.00 again.

Here is what i have so far. I am having trouble setting up three sceneraios ( he wins, he looses, or he goes onto the "point" round to win or lose). The if statement are not working correctly. I also need help in setting up a function say 'r' , which when he presses 'r' it will roll the dice for him and check. I appreciate your help, THANK YOU!

#include
#include
#include
#include


int main()
{
int firstDice, secondDice, total, secondTotal, point;
float initialMoney, finalMoney, bet, additionalBet, finalBet;


srand(time(NULL));
char answer[3];
strcpy(answer,"yes");

while(strcmp(answer,"yes")==0)
{
printf("Hello, welcome to craps. Lets bet against yourself first ");
initialMoney = 100;
printf("Here is a $ %.2f to start out ", initialMoney);
printf("How much would you like to bet? The maximum right now is $100.00 and Min is $5 ");
scanf("%f" , &bet);
printf("you bet $ %.2f ", bet);
printf("Press R to roll the dice "); // !!!NEEED HELP HERE!!!!
firstDice = (rand() % (6+1-0))+0; //first roll of dice one
secondDice = (rand() % (6+1-0))+0; //first roll of dice two
printf("The first Dice came out to be: %i ", firstDice);
printf("The second Dice came out to be: %i ", secondDice);
total = firstDice + secondDice;
printf("The total is: %i ", total);


if (total == 2 || 3 || 12 )
{
printf("you lost! ");
printf("You now have $%.2f", initialMoney-bet); //need to setup
printf("do you want to continue (yes or no) :");
scanf("%s",answer);
}

if (total == 7 || 11)
{
printf("congrats you won!!!");
printf("You now have $%.2f ", initialMoney+bet);
printf("do you want to play again (yes or no) :");
scanf("%s",answer);
}

if (total == 1 || 4 || 5 || 6 || 8 || 9 || 10)
{
point = total;
printf("do you want to increase your bet?");//need YES or NO function here
scanf("%f", additionalBet);
finalBet = bet + additionalBet;
printf("press r to roll again ");
firstDice = (rand() % (6+1-0))+0; //second roll roll of dice one
secondDice = (rand() % (6+1-0))+0; //second roll of dice two
printf("The first Dice came out to be: %i ", firstDice);
printf("The second Dice came out to be: %i ", secondDice);
secondTotal = firstDice + secondDice;

while (secondTotal == firstDice + secondDice);

if (secondTotal == 7)
{
printf("you lose! ");
printf("do you want play again? (yes or no) :");
scanf("%s",answer);
}

else if (secondTotal == point)
{
printf("you win! ");
printf("do you want play again? (yes or no) :");
scanf("%s",answer);
}

}

}


return 0;
}

Explanation / Answer

#include <stdio.h>
#include <string.h>

int main(){
   int firstDice, secondDice, total, secondTotal, point;
   float initialMoney, finalMoney, bet, additionalBet, finalBet;
   char roll, increase[10];

   srand(time(NULL));
   char answer[4];
   strcpy(answer, "yes");
   while(strcmp(answer, "yes") == 0){
       printf("Hello, welcome to craps. Lets bet against yourself first ");
       initialMoney = 100;
       printf("Here is a $ %.2f to start out ", initialMoney);
       do{
           printf(" How much would you like to bet? The maximum right now is $100.00 and Min is $5 : ");
           scanf("%f", &bet);
           if(bet < 5 || bet > 100) printf("The bet needs to be in between $ 5 and $ %.2f ", initialMoney);
       }while(bet < 5 || bet > 100);
       printf("you bet $ %.2f ", bet);
       printf("Press R to roll the dice: "); // !!!NEEED HELP HERE!!!!
       scanf(" %c", &roll);
       firstDice = rand() % 6 + 1; //first roll of dice one
       secondDice = rand() % 6 + 1; //first roll of dice two
       printf("The first Dice came out to be: %d ", firstDice);
       printf("The second Dice came out to be: %d ", secondDice);
       total = firstDice + secondDice;
       printf("The total is: %i ", total);

       if (total == 2 || total == 3 || total == 12 ){
           printf("you lost! ");
           printf("You now have $%.2f", initialMoney-bet); //need to setup
           printf("do you want to continue (yes or no) : ");
           scanf("%s", answer);
       }
       if (total == 7 || total == 11){
           printf("congrats you won!!!");
           printf("You now have $%.2f ", initialMoney+bet);
           printf("do you want to play again (yes or no) : ");
           scanf("%s", answer);
       }
       if (total == 1 || total == 4 || total == 5 || total == 6 || total == 8 || total == 9 || total == 10){
           point = total;
           printf("do you want to increase your bet? ");//need YES or NO function here
           scanf("%s", increase);
           do{
               printf("How much would you like to increase? The maximum total right now is $100.00 and Min is $5 :");
               scanf("%f", &additionalBet);
               if(bet + additionalBet < 5 || bet + additionalBet > 100) printf("The total bet needs to be in between $ 5 and $ %.2f ", initialMoney);
           }while(bet + additionalBet < 5 || bet + additionalBet > 100);
           finalBet = bet + additionalBet;
           do{
               printf("press r to roll again :");
               scanf(" %c", &roll);
               firstDice = rand() % 6 + 1; //second roll roll of dice one
               secondDice = rand() % 6 + 1; //second roll of dice two
               printf("The first Dice came out to be: %d ", firstDice);
               printf("The second Dice came out to be: %d ", secondDice);
               secondTotal = firstDice + secondDice;
               if (secondTotal == 7){
                   printf("you lose! ");
                   printf("do you want play again? (yes or no) : ");
                   scanf("%s", answer);
               }
               else if (secondTotal == point){
                   printf("you win! ");
                   printf("do you want play again? (yes or no) : ");
                   scanf("%s", answer);
               }
               else{
                   printf("Neither win nor loss. ");
               }
           }while(secondTotal != 7 && secondTotal != point);
           printf(" ");
       }
   }

   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