1. Create the following function to randomly generate numbers from
1 to 100:
generateNumber().
The function will return an integer from 1 to 100.
The program will then ask you to guess a number.
If the number is equal to the generated number, it will print message:
"Congratulations"
If the number is less than the generated number will print message:
"Too Low. Please guess again another number."
If the number is greater than the generated number it will print message:
"Too High. Please guess another number."
The objective is to use as few guesses as possible to get the right number.
Hint:
use: #include "stdlib.h" and rand() function
For example:
#include "stdlib.h"
#include "time.h"
void main()
{
srand(time(NULL));
int n = 1 + rand( )%10 //will generate number
//from 1 to 10
}
SOLUTION:
TEXT VERSION:
Add me (Healer Omega) to Facebook