Tuesday 18 November 2014

cs201 Assignment 1

A Game Generates Random Secret Number from given Range

Analysis of The Game:-

 This is a cute random number generation game. We have following terms for the game.
  1. The user gives the input to the game in the form of random numbers i.e Lower Limit and Upper Limit. 
  2. Then the computer Generates a random secret Number and stores it in its memory. 
  3. The computer then asks the user to guess the Number by a prompt. 
  4. If the user Number is less then the secret Number it Returns a Message. 
  5. If The Number is Equal To the Number it gives the 2nd Message. 
  6. If Number is Greater then the Secret Number it shows the Third Message.

The Process Involved in the Game:-

The game includes following header files atleast
#include<iostream.h>
#include<stdio.h>
using namespace std;

The process of the game usually starts with the main function.
main( )
{
}
Now as we analyze earlier we have 4 integer values in the game
int SecertNumber
int UserNumber
int LowerLimit
int UpperLimit

  1. The secret number is the number generated by computer.
  2. The user Number is the number asked by the computer as a guess. So user will input that number.
  3. The LowerLimit and UpperLimit are also prompted from user.
  4. Note that all number should be equalize to 0 while defining.
Now when we have defined the integers we can move on with building our program.

ask the user to enter upper and lower limits at this stage

cout << "Please Enter the Lower Limit="
cin >> LowerLimit

cout << "Please Enter the Upper Limit="
cin >> UpperLimit

Now it is the Time to Generate a Random Secret Number

srand(time(NULL))
SecretNumber = rand()%upperlimit+lowerlimit
cout<<"Done!"<<endl<<endl

Well NOW ONLY THING YOU NEED IS TO GENERATE THE TEST FOR YOUR RANDOM GENERATED NUMBER

ask the user to Guess the secret number

cout << "Please guess the secret Number"
cin >> UserNumber

NOW USE IF , ELSE IF and ELSE To show weather the Number is > then SecretNumber, OR IT IS > then SecretNumber or == to the SecretNumber

HURRAH HERE GOES THE CODE FOR THE GAME.

.
.
.

THANKS TO OUR TEAM IN THE BASEMENT