[ create a new paste ] login | about

Link: http://codepad.org/HlGCiVoP    [ raw code | output | fork ]

C++, pasted on Jul 12:
#include <iostream>
#include <cstdlib>
#include <ctime>

int main()
{
	srand((unsigned int)time(NULL)); // these 2 lines create a random number.
	int randomNumber = rand() % 101;

	std::cout << "Guess a number which is greater or less than 50" << std::endl;
	std::cout << "If less than 50 then press 0 or if greater than 50 then press 1: ";
	int inputFromUser;
	std::cin >> inputFromUser;

	if (inputFromUser == 0)
	{
		if (randomNumber < 50)
		{
			std::cout << "Correct! The random number is " << randomNumber << " less than 50." << std::endl;
		}
		else if (randomNumber > 50)
		{
			std::cout << "Fail! The random number is " << randomNumber << " greater than 50." << std::endl;
		}
		else
		{
			std::cout << "Woa! The random number is 50." << std::endl;
		}
	}

	else if (inputFromUser == 1)
	{
		if (randomNumber < 50)
		{
			std::cout << "Fail! The random number is " << randomNumber << " less than 50." << std::endl;
		}
		else if (randomNumber > 50)
		{
			std::cout << "Correct! The random number is " << randomNumber << " greater than 50." << std::endl;
		}
		else
		{
			std::cout << "Woa! The randam number is 50." << std::endl;
		}
	}

	else
	{
		std::cout << "Only 1 or 0! Please try again." << std::endl;
	}
	

	system("Pause");
	return 0;
}


Output:
1
2
3
4
Guess a number which is greater or less than 50
If less than 50 then press 0 or if greater than 50 then press 1: Correct! The random number is 3 less than 50.

Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: