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.- The user gives the input to the game in the form of random numbers i.e Lower Limit and Upper Limit.
- Then the computer Generates a random secret Number and stores it in its memory.
- The computer then asks the user to guess the Number by a prompt.
- If the user Number is less then the secret Number it Returns a Message.
- If The Number is Equal To the Number it gives the 2nd Message.
- 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
- The secret number is the number generated by computer.
- The user Number is the number asked by the computer as a guess. So user will input that number.
- The LowerLimit and UpperLimit are also prompted from user.
- Note that all number should be equalize to 0 while defining.
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.
.
.
.
No comments:
Post a Comment