In: Computer Science
Write in C programming using if and else statements only please!!!
Write a program that plays the following card game: The user starts out with a pot of $100. At each hand of the game, the dealer and the player are dealt a random number between 1 and 52. The player wins $20 if his/her number is greater than the dealer's number; otherwise they lose $20.
C Code:
#include <stdio.h>
int main()
{
int balance=100,dealer,player,flag;
while(1)
{
printf("Enter the number of dealer between 1 to 52:");
scanf("%d",&dealer);
printf("Enter the number of player between 1 to 52:");
scanf("%d",&player);
if(dealer<=0 || dealer>52 || player<=0 || player>52
)
continue;
if(player>dealer)
{
balance=balance+20;
printf("User won\n");
}
else
{
balance=balance-20;
printf("User lost\n");
}
printf("Remaining amount in users pot:%d\n",balance);
if(balance==0)
break;
printf("Enter 0 if you want to exit the game or enter any number to
continue:");
scanf("%d",&flag);
if(flag==0)
break;
}
printf("Finally Remaining amount in users
pot:$%d\n",balance);
return 0;
}
Output:
If you want any modifications please let me know comment below.