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

Design a C program that simulates a slot machine. When the program runs, it shou

ID: 3547729 • Letter: D

Question

                    Design a C program that simulates a slot machine. When the program runs, it should do one of the following:                 

                    1. Ask the user to enter the amount of money he or she want to insert into the slot machine.                 

                    2. Instead displaying images, the program will randomly select a word from the following list: Cherries, Oranges, Plums, Bells, Melons,                     Bars.                 

                    The program will select and display a word from this list three times.                 

                    4. If none of the randomly selected words match, the program will inform the user that he or she has won $0. If two of the words match, the                     program will inform the user that he or she has won two times the amount entered. If three of the words match, the program will inform the user that he or she                     has won three times the amount entered.                 

                    5. The program will ask whether the user wants to play again. If so, these steps are repeated. If not, the program displays the total amount                     of money entered in the slot machine and the total amount won.                 

Explanation / Answer

#include<stdio.h>

int main()

{

int flag1=1;

while(flag1)

{

int x,y,money,flag=0,a[6]={0},v;

scanf("%d",&money);

int count=0;

while(count<3)

x=rand()%6;

if(x==0)

{

printf("Cherries ");

a[x]++;

if(a[x]>flag)

flag=a[x];

}

else if(x==1)

printf("Oranges ");

a[x]++;

if(a[x]>flag)

flag=a[x];

}

else if(x==2)

printf("Plums ");

a[x]++;

if(a[x]>flag)

flag=a[x];

}else if(x==3)

printf("Bells ");

a[x]++;

if(a[x]>flag)

flag=a[x];

}else if(x==4)

printf("Melons ");

a[x]++;

if(a[x]>flag)

flag=a[x];

}else if(x==5)

printf("Bars ");

a[x]++;

if(a[x]>flag)

flag=a[x];

}

count++;

}

if(flag==1)

printf("You Won 0$ ");

else if(flag==2)

printf("You won %d$ ",2*Money);

else

printf("You won %d$ ",3*Money);

printf("Do you wish to continue??? Press 1 for yes and 0 for No ");

scanf("%d",&v);

if(v==0)

flag1=0;

}

return 0;

}