im trying to write a program using the rand() function the computer has to guess the number 30 for the loop to end...can anyone help???? this is what i have so far...not much i know.
// die roller
// demonstration
#include <iostream>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main()
{
srand(time(0));
int randomNumber = rand() % 100 + 1; // guess a random number 1 - 100
int guessCount = 0; // keep track of how many guesses it takes
while(randomNumber != 30) // loop until the computer guesses 30
{
randomNumber = rand() % 100 + 1; // new random number
cout << randomNumber << endl; // print it out
guessCount++; // increase guess count
}
// if it gets here, it guessed correctly
cout << "Took " << guessCount << " guesses\n";
return 0;
}
so your using % modulus to narrow the random number spectrum to 100? correct? is there a way i can try to get the computer to guess the number out of rand_max? or 32,767?