Answer to Question #287863 in C++ for Sagheer

Question #287863

Suppose you're asked to design a game p whether he/she wants to play a game or not. If ye the payment, the program will generate a random ask the player to input a number. If the entered random number, then give 20 points to the player scores become below or equal to 0 or the scores game and display the amount win by the player.


1
Expert's answer
2022-01-16T13:04:28-0500
#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{
	
	char choice;
	int scores=0;
	do
	{
		cout << "\nDo you want to play game?[Y/N]:";
		cin >> choice;
		if (choice != 'n' &&choice != 'N')
		{
			cout << "\n***Game guess the number***";
			cout << "\nPlease, pay the fee (1 attempt 20 units)";
			int fee;
			cout << "\nYour payment:";
			cin >> fee;
			int n;//number to guess
			if (fee >= 20)
			{
				cout << "\nThe computer guessed the number from 0 to 10";
				n = rand() % 10;
				cout << "\nTry to guess it: ";
			}
			while (fee >= 20)
			{
				fee -= 20;
				int guess;
				cin >> guess;
				if (n == guess)
				{
					cout << "\nCongratulations! You won!";
					scores += 20;
					break;
				}
				else if(fee>=20)
				{
					cout << "\nError, try again:";
				}
				else
				{
					cout << "\nUnfortunatelly you lost!";
					break;
				}
			}
			
		}
	} while (choice != 'n' &&choice != 'N');
	
	cout << "\nYour scores are " << scores;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment