In: Computer Science
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)
NetBeans.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int win = 0, loss = 0, total = 0, num, n;
string st;
while (1)
{
num = rand() % 11 + 1;
cout << "Enter guess number:\n";
cin >> n;
while (n < 1 or n > 10)
{
cout << "Invalid! number Enter again:\n";
cin >> 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;
}
cout << "Enter yes to continue or no to quit:\n";
cin >> st;
if (st == "NO" || st == "no")
break;
}
cout << "Total games:" << total << "\n";
cout << "Total wins:" << win << "\n";
cout << "Total loss:" << loss << "\n";
return 0;
}
******************************************************************************************
PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT
SECTION
******************************************************************************************