##### Question

In: Computer Science

# C++ Create a program that simulates a coin being flipped. Ask the user to guess between...

C++

Create a program that simulates a coin being flipped. Ask the user to guess between heads and tails. Let the user input 0 for heads and 1 for tails.

Use a random generator to get random guesses every time.

If the user guesses correctly, give them 1pt. Use a counter and initialize it to 0.

If the user does not guess correctly, subtract a point.

Create a menu that allows the user to continue guessing, view the current score or quit guessing.

Note: You can use classes, pointers... Do not go beyond that. Keep code simple.

## Solutions

##### Expert Solution

include<iostream>
using namespace std;
int coinToss(void) {
int flip;
flip = rand()%2  ;

return flip;
}
int main()
{
int flip,Count=0,errorCount=0,guess,score=0,choice;

while(1)
{
cout<< "press 1 to continue guessing: "<< endl;
cout<< "press 2 to view the current score: "<< endl;
cout<< "press 3 to quit guessing: "<< endl;
cin>> choice;
switch(choice) {
case 1:
cout<<" enter 0 to guess head or enter 1 to guess tail ";
cin >> guess;

flip = coinToss();
if(flip == 0)
cout<< "the result is head" << endl;
else
cout<< "the result is tail"<< endl;
if(flip == guess)
{
cout<< " your guess is correct" << endl;
Count += 1;
} else {
cout<< " your guess is wrong" << endl;
errorCount += 1;
}
break;

case 2:
score = score + (Count *1) -(errorCount *1);
cout<< "your current score is " << score << endl;
break;
case 3:
cout<< "Thank You for your participation" << endl;
exit(0);
}
}
return 0;
}

Sample Output :

## Related Solutions

##### In C++  Write a program that simulates coin tossing. For each toss of the coin the program...
In C++  Write a program that simulates coin tossing. For each toss of the coin the program should print heads or tails. Let the program toss the coin 100 times and count the number times each side of the coin appears. Print the results. 0 represents tails and 1 for heads.
##### Create a C++ program that will ask the user for how many test scores will be...
Create a C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. (no fstream) The data needs to include the student’s first name, student number test score the fields should be displayed with a total width of 15. The prompt should be printed with a header in the file explaining what each is: ex. First Name student number Test Score 1) mike 6456464   98 2) phill...
##### Write a C program that asks the user to guess a number between 1 and 15(1...
Write a C program that asks the user to guess a number between 1 and 15(1 and 15 are included). The user is given three trials. This is what I have so far. /* Nick Chioma COP 3223 - HW_2 */ #include <iostream> #include <time.h> // needed for time function #include <stdlib.h> // needed for srand, rand functions int main () {       int numbertoguess, num, correct, attempts;       srand(time(NULL)); //this initializes the random seed, making a new...
##### Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
##### Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
##### Create a PYTHON program that lets a user guess a number from 1 to 1,000: -i...
Create a PYTHON program that lets a user guess a number from 1 to 1,000: -i used random.randint(1,1000) -must give hints like (pick a lower/higher number) which i already did -tell the user when he has repeated a number (help) -the game only ends when you guess the number (help) -you loose \$50 every failed attempt (done) ****I did it as a while loop -
##### Write an application that simulates coin tossing. Let the program toss a coin each time the...
Write an application that simulates coin tossing. Let the program toss a coin each time the user chooses the “Toss Coin” menu option. Count the number times each side of the coin appears. Display the results. The program should call a method flip( ) that takes no arguments and returns a zero to represent a tail or a one to represent a head. There is a Random class that will allow you to generate a random integer. Import it from...
##### Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
##### C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
##### Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...