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

Objective - creating a simple slot machine. The machine should ask the user how

ID: 2081258 • Letter: O

Question

Objective - creating a simple slot machine. The machine should ask the user how much money he/she is willing to Deposit. The machine should ask the user how much money he/she is willing to Bet per each round. The slot machine will display 3 numbers 0, 1, and 2. The choice of these numbers should be decided by rand() function in c. [How to use rand() function in c a. Num = rand()%3;//This line will generate a number between 0,1, and 2 and assign the number to Num variable b. rand() requires #include The choice of these 3 numbers should be computed outside of main() function - in other words, use the USER defined function. Each round, the Deposit will be deducted by the amount of the Bet When first two numbers match, the user will receive xl of the Bet When all three numbers match, the user will receive x2 of the Bet. *So, conditions 6, 7, and 8 express the rule of gambling. No matches, you will lose the Bet money (Deposit - Bet) First two numbers match, you will break even (Deposit - Bet + Bet) When 3 numbers match you make some (Deposit - Bet + 2 x Bet) After each round, the user should be prompted whether he/she would like to play more. If the Deposit money runs out, the game should end automatically.

Explanation / Answer

C Code:

#include <stdio.h>
#include <stdlib.h>

int out(); //function declaration
int main()
{
float Deposit, Bet;
int Num[3],i;
char choice;
printf("Enter Deposit Amount: ");
scanf("%f",&Deposit);
printf("Enter Bet Amount per round: ");
scanf("%f",&Bet);
do
{

printf("New Round begins... ");
Deposit = Deposit - Bet;
for (i=0;i<=2;i++)
{
Num[i] = out();
printf("Number %d: %d ",i+1,Num[i]);
}
if (Num[0]==Num[1]) //checking if first 2 numbers match
{
Deposit += Bet;
if (Num[1]== Num[2]) // checking if all numbers match
{
Deposit += Bet;
}
}
else
{
printf("Better luck next time ");
}
printf("Round ends ");
printf("Deposit Amout: %.0f ",Deposit);
if (Deposit >= Bet)
{
printf("Would you like to try again? Enter y/n : ");
getchar();
choice = getchar();
}
else
{
printf(" Game Over ");
choice = 'n';
}
}while(choice == 'y');
printf(" Game Over ");
return 0;
}

int out()
{
int x;
x = rand()%3;
return x;
}