Question

In: Computer Science

Write a program that prompts the user to enter a number within the range of 1...

Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive • The program then generates a random number using the random class: o If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number o If the users guess matches the random number tell them they win! o If the users guess does not match the random number tell them they are wrong • Use a loop (WHILE or DO) to allow the program to be repeated by typing in the word “YES” ignore case sensitivity • Ensure that every time you repeat a NEW random number is generated • Increment the appropriate variables upon the following instances: o A win (add 1 to winCount) o A loss (add 1 to lossCount) o New game played (add 1 to playCount) • At the end of the program neatly display the user their stats (Their times played, their win count and their losses)

Solutions

Expert Solution

here is the solution in c++

here is the code

#include <iostream>
#include<string>
using namespace std;
int main()
{ //variables declaration
int win=0,loss=0,total=0,num,n;
string st;
while(1)
{ //generate random number
num=rand()%11+1;
cout<<"Enter guess number:\n";
cin>>n;
//number validation
while(n<1 or n>10)
{
cout<<"Invalid! number Enter again:\n";
cin>>n;
}
//check if guess isequal to n
if(n==num)
{
cout<<"you won!\n";
win=win+1;
total=total+1;
}
else
{
cout<<"Answer is wrong.You loss\n";
loss=loss+1;
total=total+1;
}
//take user choice
cout<<"Enter yes to continue or no to quit:\n";
cin>>st;
if(st=="NO" or st=="no")
break;
}//display the stats
cout<<"Total games:"<<total<<"\n";
cout<<"Total wins:"<<win<<"\n";
cout<<"Total loss:"<<loss<<"\n";
return 0;
}


Related Solutions

Write a program that prompts the user to enter a number within the range of 1...
Write a program that prompts the user to enter a number within the range of 1 to 10 inclusive • The program then generates a random number using the random class: o If the users guess is out of range use a validation loop (DO) to repeat the prompt for a valid number o If the users guess matches the random number tell them they win! o If the users guess does not match the random number tell them they...
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
In Java: Write a program that prompts the user to enter a positive number until the...
In Java: Write a program that prompts the user to enter a positive number until the user input a negative number. In the end, the program outputs the sum of all the positive numbers. You should use do-while loop (not while, not for). You cannot use break or if statement in the lab. Hint: if the program adds the last negative number to your sum, you can subtract the last number from the sum after the loop.
Problem 1 Write a program that prompts the user to enter an integer It then tells...
Problem 1 Write a program that prompts the user to enter an integer It then tells the user if the integers is a multiple of 2, 3, 5, 7 or none of the above. Program language is C Ex. Enter an integer 12 You entered 12 The number you entered is a multiple of 2 ----------------------------------------------- Enter an integer 11 You entered 11 The number you entered is not a multiple of 2, 3, 5, or 7
Write a program that prompts the user to enter an integer from 1 to 15 and...
Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid, as shown in the following sample run: here............THE PYRAMID HAS TO BE THIS SHAPE AND IT IS DONE IN JAVA PLEASE 7 6 5 4 3 2 1 2 3 4 5 6 7 6 5 4 3 2 1 2 3 4 5 6 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4...
C++ [2] Write a program that prompts the user to enter a non-negative decimal number and...
C++ [2] Write a program that prompts the user to enter a non-negative decimal number and a base in the range 2 <= base <= 16. Write a function multibaseOutput() that displays the number in the specified base. The program terminates when the user enters a number of 0 and a base 0. Run: Enter a non-negative decimal number and base (2 <= B <= 16) or 0 0 to terminate: 155 16     155 base 16 is 9B Enter...
C Program 1. Write a program that prompts the user to enter 3 integers between 1...
C Program 1. Write a program that prompts the user to enter 3 integers between 1 and 100 from the keyboard in function main and then calls a function to find the average of the three numbers. The function should return the average as a floating point number. Print the average from main.The function header line will look something like this:float average(int n1, int n2, int n3) STOP! Get this part working before going to part 2. 2. Create a...
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
Problem 4 : Write a program that prompts the user to enter in an integer and...
Problem 4 : Write a program that prompts the user to enter in an integer and then prints as shown in the example below Enter an integer 5 // User enters 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Bye
Write a program that prompts the user to enter a series of strings, but with each...
Write a program that prompts the user to enter a series of strings, but with each string containing a small integer. Use a while loop and stop the loop when the user enters a zero. When the loop has finished, the program should display: the number of user inputs (not counting the final zero input). the total of the integers in the strings entered. the average of the integers accurate to one decimal place. Any help is greatly appreciated, this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT