Guess The Number – C++

What it does:
Another program which I created in labs in uni, as a task. It randomly generates a number, the user would then enter a guess and it would return either too low or too high allowing them to decide whether or not they need to increase or decrease their guess.


#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>

using namespace std;

int main()
	int randomNumber = rand()%100;
	int userGuess;
		cout << "\nPlease enter a number between 0 and 100" << endl;
		cin >> userGuess;
			cout << "Your guess is too high" << endl;
		else if(userGuess<randomNumber)
			cout << "Your guess is too low" << endl;
		}//else if
	while(randomNumber!= userGuess);
	cout << "\n Your guess is correct and your number was " << userGuess << endl;
	return 0;

3 thoughts on “Guess The Number – C++

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s