Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.6 kB
3
Indexable
Never
#include <iostream>
#include <string>
#include <ctime>
#include <exception>

using namespace std;

//Win Function
int win() {
	cout << "You guessed the correct answer! Congratulations!\n\n";
	system("pause");
	exit(0);
	return 0;
	
		}



int main() {

	// User Answers
	int answer1;
	int answer2;
	int answer3;

	//Retry Flag
	char playagain;

	do {
		// Random Number Generation
		srand(time(NULL));
		unsigned int randomnumber = (rand() % 10) + 1;

		cout << "           Guess Game            \n";
		cout << "          ************          \n\n";
		cout << "You will get three chances to guess the number. \n\n";
		cout << "Guess a number in between 1 to 10. \n\n\n";
		cout << "Choice 1 : Enter your answer  : ";
		cin >> answer1;

		if (answer1 != randomnumber) {
			cout << "\nSorry wrong guess, Try Again \n\n";
		}
		else if (answer1 == randomnumber) {
			win();
		}

		cout << "Choice 2 : Enter your answer  : ";
		cin >> answer2;

		if (answer2 != randomnumber) {
			cout << "\nSorry wrong guess, Try Again \n\n";

		}
		else if (answer2 == randomnumber) {
			win();
		}

		cout << "Choice 3 : Enter your answer  : ";
		cin >> answer3;

		if (answer3 != randomnumber) {
			cout << "\nSorry wrong guess, You reached the limit \n\n\n";
			cout << "Correct number : " << randomnumber << "\n\n";
		}
		else if (answer3 == randomnumber) {
			win();
		}

		cout << "Play again ? y/n ";
		cin >> playagain;
		cout << "\n\n";

} while (playagain == 'Y' || playagain == 'y');
			cout << "Goodbye.\n\n";
		system("PAUSE");
		return 0;
	}