• Create Account

### #ActualMoonkis

Posted 02 July 2012 - 07:50 AM

Think of it as this, the computer guesses a random number ( using the rand() % 100 + 1 ) then you check if it's higher, lower or correct.
This can be done with some sort of loop.

For example a while loop:
Pseudo-code(ish):
int guess = rand() % 100 + 1 // Get the initial guess from the computer
while(true)
{
if(guess < choosenNumber) {
cout << "That is to low!" << endl;
guess = rand() % 100 + choosenNumber;
}
else  if(guess > choosenNumber) {
cout << "That is to high!" << endl;
guess = rand() % choosenNumber + 1;
}
else
{
cout << "The correct number was guessed" << endl;
return;
}
}


### #1Moonkis

Posted 02 July 2012 - 07:49 AM

Think of it as this, the computer guesses a random number ( using the rand() % 100 + 1 ) then you check if it's higher, lower or correct.
This can be done with some sort of loop.

For example a while loop:
Pseudo-code(ish):
int guess = rand() % 100 + 1 // Get the initial guess from the computer
while(true)
{
if(guess < choosenNumber) {
cout << "That is to low!" << endl;
guess = rand() % choosenNumber +1;
}
else  if(guess > choosenNumber) {
cout << "That is to high!" << endl;
guess = rand() % 100 + choosenNumber;
}
else
{
cout << "The correct number was guessed" << endl;
return;
}
}


PARTNERS