Good afternoon. I need some help manipulating this program. Its written in C pro
ID: 3741165 • Letter: G
Question
Good afternoon. I need some help manipulating this program.
Its written in C programming.
In codeblocks.
I need so my script is a user defined function that does not take argument but returns value.
Thanks in advance.
#include <stdio.h>
#include <stdlib.h>
int main(){
int i,j;
char yesorno = 'Y';
int deposit;
int bet;
int slotnumbs[3];
int gameOver =0;
printf("Lets play Slot Machine - Viva Las Vegas! ");
printf("How much deposit will you make? ");
scanf("%d",&deposit);
while(gameOver!=1){
slotnumbs[i]=rand()%3;
for(i=0;i<3;i++){
}
printf("How much bet will you make this time? ");
scanf("%d",&bet);
printf("------------------------------------------------------------------- ");
printf("| %d | %d | %d | ",slotnumbs[0],slotnumbs[1],slotnumbs[2]);
if(slotnumbs[0] == slotnumbs[1] && slotnumbs[0] == slotnumbs[2]){
printf("Congratulations! You have ALL 3 numbers matching! ");
printf("You earned %d in this Round! ",bet+bet);
deposit=bet+bet;
printf("Your current balance is %d! ",deposit);
}
else if(slotnumbs[0]==slotnumbs[1]){
printf("Congratulations! You have the FIRST 2 numbers matching! ");
printf("You earned %d in this Round! ",bet+bet);
deposit=bet;
printf("Your current balance is %d! ",deposit);
}
else{
printf("Sorry you didnt earn anything ");
printf("Your current balance is %d! ",deposit-bet);
}
if(deposit==0){
gameOver=1;
printf("You've ran out of funds. GG - Good game, better luck next time! ");
}
printf("Do you wish to continue? ");
printf("Type N if you wish to stop ");
scanf("%c",&yesorno);
if(yesorno=='N' || yesorno=='n'){
gameOver = 1;
printf("Sorry to see you go, but I know you made a sane choice. ");
}
}
getchar();
return 0;
}
Explanation / Answer
The code is
#include<stdio.h>
#include<stdlib.h>
int deposit;
int game()
{
int i,j;
char yesorno = 'Y';
int bet;
int slotnumbs[3];
for(i=0;i<3;i++)slotnumbs[i]=rand()%3;
printf("How much bet will you make this time? ");
scanf("%d",&bet);
printf("------------------------------------------------------------------- ");
printf("| %d | %d | %d | ",slotnumbs[0],slotnumbs[1],slotnumbs[2]);
if(slotnumbs[0] == slotnumbs[1] && slotnumbs[0] == slotnumbs[2]){
printf("Congratulations! You have ALL 3 numbers matching! ");
printf("You earned %d in this Round! ",bet+bet);
deposit=bet+bet;
printf("Your current balance is %d! ",deposit);
}
else if(slotnumbs[0]==slotnumbs[1]){
printf("Congratulations! You have the FIRST 2 numbers matching! ");
printf("You earned %d in this Round! ",bet+bet);
deposit=bet;
printf("Your current balance is %d! ",deposit);
}
else{
printf("Sorry you didnt earn anything ");
printf("Your current balance is %d! ",deposit-bet);
}
if(deposit==0){
printf("You've ran out of funds. GG - Good game, better luck next time! ");
return 1;
}
printf("Do you wish to continue? ");
printf("Type N if you wish to stop ");
scanf("%c",&yesorno);
if(yesorno=='N' || yesorno=='n'){
printf("Sorry to see you go, but I know you made a sane choice. ");
return 1;
}
}
int main(){
int gameOver =0;
printf("Lets play Slot Machine - Viva Las Vegas! ");
printf("How much deposit will you make? ");
scanf("%d",&deposit);
while(gameOver!=1)
{
gameOver=game();
}
getchar();
return 0;
}
Do give a thumbs up and in case there are doubts leave a comment
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.