Question

In: Computer Science

Write in C programming using if and else statements only please!!! Write a program that plays...

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.

Solutions

Expert Solution

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.


Related Solutions

write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
This is for Java programming. Please use ( else if,) when writing the program) Write a...
This is for Java programming. Please use ( else if,) when writing the program) Write a java program to calculate the circumference for the triangle and the square shapes: The circumference for: Triangle = Side1 + Side2 +Sid3 Square = 4 X Side When the program executes, the user is to be presented with 2 choices. Choice 1 to calculate the circumference for the triangle Choice 2 to calculate the circumference for the square Based on the user's selection the...
Write a program in c++ using only if statements that prompts the user to enter an...
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week. The future day can be computed as follows: (today + number of days after today) % 7 Sample run...
In C++ Please, using only the libraries given in this homework prompt, Write a program that...
In C++ Please, using only the libraries given in this homework prompt, Write a program that (1) prompts for two integers, (2) prints out their sum, (3) prints out the first divided by the second, and (4) prints out the natural log of the first number raised to the power of the second number. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes here> return 0; }
Please write a C++ program to find the largest number among three numbers using nested if...else...
Please write a C++ program to find the largest number among three numbers using nested if...else statements You need to prompt the user to enter three integer numbers from the keyboard, and then display the largest number among the three. Please create a function to find the largest number among three numbers, and call the maxAmongThree function in the main function.
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
Develop a C++ program that plays out a round of Rock, Paper, Scissors using Functional Programming...
Develop a C++ program that plays out a round of Rock, Paper, Scissors using Functional Programming 1) Develop a function that prompts the user to enter their choice (1=Rock 2=Paper 3=Scissors) Return either a 1, 2, or 3 depending on the value the user has entered Do not continue the program until the user has entered a valid choice of 1, 2, 3 2) Develop a function that generates the computer player's choice Return either a 1, 2, or 3...
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
(using for loop, parameters, if, else condition only )Python: Write a program that prompts the user...
(using for loop, parameters, if, else condition only )Python: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: • If the value is even, halve it. • If it's odd, multiply by 3 and add 1. • Repeat this process until the value is 1, printing out each value. • Then print out how many of these operations you performed. If the input value is less than 1, print a message...
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude...
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude <iostream>)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT