C Program Name Payout Odds of winning Horse 1 Payout 2-1 40% Horse 2 Payout 5-1
ID: 3594463 • Letter: C
Question
C ProgramName Payout Odds of winning Horse 1 Payout 2-1 40% Horse 2 Payout 5-1 10% Horse 3 Payout 10-1 8% Horse 4 Payout 15-1 6% Horse 5 Payout 50-1 1% Horse 6 Payout 20-1 4% Horse 7 Payout 10-1 8% Horse 8 Payout 5-1 10% Horse 9 Payout 3-1 13% Your program should use the above payout and odds chart. You need to allow a user to add money to his or her bank. You will assume the person starts with no money in their wallet. If the person runs out of money in their bank and wallet he or she cannot play. The person can never bet more money than they have. The program should allow the person to see their bank balance at anytime. The program should allow a deposit or withdraw to be made from the bank at anytime. The money goes in and out of the wallet. The program will allow the person to make a bet and pick a horse...once the bet is placed the program will run the race. Once the race is done the wallet will be updated and a message will be displayed such as Horse 5 won the race you lost XXX dollars -OR- Congratulations your horse "Horse 7" won...you have just won $XXX dollars. You now have $XXX in your wallet. My guess is you gotta allow them to quit...and so on. C Program
Name Payout Odds of winning Horse 1 Payout 2-1 40% Horse 2 Payout 5-1 10% Horse 3 Payout 10-1 8% Horse 4 Payout 15-1 6% Horse 5 Payout 50-1 1% Horse 6 Payout 20-1 4% Horse 7 Payout 10-1 8% Horse 8 Payout 5-1 10% Horse 9 Payout 3-1 13% Your program should use the above payout and odds chart. You need to allow a user to add money to his or her bank. You will assume the person starts with no money in their wallet. If the person runs out of money in their bank and wallet he or she cannot play. The person can never bet more money than they have. The program should allow the person to see their bank balance at anytime. The program should allow a deposit or withdraw to be made from the bank at anytime. The money goes in and out of the wallet. The program will allow the person to make a bet and pick a horse...once the bet is placed the program will run the race. Once the race is done the wallet will be updated and a message will be displayed such as Horse 5 won the race you lost XXX dollars -OR- Congratulations your horse "Horse 7" won...you have just won $XXX dollars. You now have $XXX in your wallet. My guess is you gotta allow them to quit...and so on.
Name Payout Odds of winning Horse 1 Payout 2-1 40% Horse 2 Payout 5-1 10% Horse 3 Payout 10-1 8% Horse 4 Payout 15-1 6% Horse 5 Payout 50-1 1% Horse 6 Payout 20-1 4% Horse 7 Payout 10-1 8% Horse 8 Payout 5-1 10% Horse 9 Payout 3-1 13% Your program should use the above payout and odds chart. You need to allow a user to add money to his or her bank. You will assume the person starts with no money in their wallet. If the person runs out of money in their bank and wallet he or she cannot play. The person can never bet more money than they have. The program should allow the person to see their bank balance at anytime. The program should allow a deposit or withdraw to be made from the bank at anytime. The money goes in and out of the wallet. The program will allow the person to make a bet and pick a horse...once the bet is placed the program will run the race. Once the race is done the wallet will be updated and a message will be displayed such as Horse 5 won the race you lost XXX dollars -OR- Congratulations your horse "Horse 7" won...you have just won $XXX dollars. You now have $XXX in your wallet. My guess is you gotta allow them to quit...and so on. Name Payout Odds of winning Horse 1 Payout 2-1 40% Horse 2 Payout 5-1 10% Horse 3 Payout 10-1 8% Horse 4 Payout 15-1 6% Horse 5 Payout 50-1 1% Horse 6 Payout 20-1 4% Horse 7 Payout 10-1 8% Horse 8 Payout 5-1 10% Horse 9 Payout 3-1 13% Your program should use the above payout and odds chart. You need to allow a user to add money to his or her bank. You will assume the person starts with no money in their wallet. If the person runs out of money in their bank and wallet he or she cannot play. The person can never bet more money than they have. The program should allow the person to see their bank balance at anytime. The program should allow a deposit or withdraw to be made from the bank at anytime. The money goes in and out of the wallet. The program will allow the person to make a bet and pick a horse...once the bet is placed the program will run the race. Once the race is done the wallet will be updated and a message will be displayed such as Horse 5 won the race you lost XXX dollars -OR- Congratulations your horse "Horse 7" won...you have just won $XXX dollars. You now have $XXX in your wallet. My guess is you gotta allow them to quit...and so on.
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
float balance =0.0;
void display_bal(float balance)
{
printf(" Your current balance is : %f",balance);
}
void withdraw(float balance,float amount)
{
if(balance>=amount)
{
balance -= amount;
display_bal(balance);
}
else
{
printf("You have insufficient balance");
}
}
void deposit(float balance,float amount)
{
if(amount>0)
{
balance += amount;
display_bal(balance);
}
else
{
printf("please enter valid amount");
}
}
void bet(int horse,float amount,float balance)
{
if(balance>amount)
{
int payout[10]={2,5,10,15,50,20,10,5,3};
printf("You have bet %f amount on horse %d your new balance is ",amount,horse);
withdraw(balance,amount);
int n=rand() %9 +1;
if(n==horse)
{
balance += amount*payout[n-1];
printf(" Congratulations your horse "Horse %d" won...you have just won $%f dollars. You now have $%f in your wallet.",n,amount*payout[n-1],balance);
}
else
{
printf(" Horse %d won the race you lost %f dollars ",n,amount);
}
}
}
int main (void)
{
int menu,horse;
float amount;
do
{
printf(" Enter 1 to display your balance 2 to deposit 3 to withdraw 4 to play bet game 5 to exit");
scanf("%d",&menu);
switch(menu)
{
case 1:display_bal(balance);
break;
case 2:printf(" Enter amount to deposit to your wallet: ");
scanf("%f",&amount);
deposit(balance,amount);
break;
case 3:printf(" Enter amount to withdraw from your wallet: ");
scanf("%f",&amount);
withdraw(balance,amount);
break;
case 4:printf(" Enter horse number and amount that you want to bet");
scanf("%d %f",&horse,&amount);
bet(horse,amount,balance);
break;
case 5: return 0;
default:printf(" Invalid input, try again");
}
}while(menu!=5 || balance>0);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.