Number Guessing Game Documentation - jordoncotton/IntrotoC- GitHub Wiki

Number Guessing Game Documentation

Jordon Cotton

Matthew Williamson

s188044

Intro C++

I. 1 Description of Problem

Name: Number Guessing Game

Problem Statement: Number Guessing Game will generate a random number allowing the user to choose a number from 1-20. It will then give the user a hint of, if secret number is less than, greater than or equal to the random number.

Problem Specifications: Must use the following

  • You are to create a program that will correctly identify the number a user is thinking.

  • The program will prompt the user to think of a number.

  • Once the user has thought of a number the user must tell the computer to begin guessing.

  • The computer will begin guessing numbers by printing it's guess to the console.

  • After each guess, the user must tell the computer if the guessed number is less than, greater than, or equal to the number the user is thinking.

  1. Variables
  2. Conditionals
  3. Loops
  4. The number that the user is thinking
  5. The computer has guessed the correct number
  6. Application is forced to quit

I. 2 Input Information

  • N/A

I. 3 Output Information

  • The program will start off by the user clicking the executable and running it. Then it will start with asking the player to choose a number from 1 to 20.
  • Once the user has guessed there number the program will tell that user if there number is greater than or less than the secret number.
  • When the user guesses the correct number it will congratulate the user and you will press any key to continue and end the program.

I. 4 User Interface Information

  • The user will enter there guess until they have chose the correct number.
  • User will press continue to end program.
  • If user wants to play again then the user will need to rerun the program.

II. Design

II. 1 System Architecture

int Main()

II. 2 User Interface

User Interface gif

III. Source Code

#include <iostream>
#include <ctime>
#include <cstdlib>

int main()
{
	// System generates a random number.
	srand(time(0));
	int number;
	number = rand() % 20 + 1;
	// Computer guess a random number and user tries to guess that random number.
	//char input = guess a number 1-800.
	int input;
	std::cout << "Guess a number 1-20! Input your answer" << std::endl;

	do
	{
		std::cin >> input;

		if (input < number)
		{
			std::cout << "Your estimate is less, than the secret number" << std::endl;
		}
		else if (input > number)
		{
			std::cout << "Your estimate is more, than the secret number" << std::endl;
		}
		else
		{
			std::cout << "Your guess is right!" << std::endl;
		}
	} while (input != number);

	system("PAUSE");

	return 0;
}
⚠️ **GitHub.com Fallback** ⚠️