Im trying to make the computer guesss a number i input in the fewest amount of guessed. now we are not in that complicated of a class but here is my code
//comp guess my number
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int guess, original_number, tries, guess2;
srand(time(0));
tries = 0;
cout << "Please enter a number you want the computer to guess(1-100): ";
cin >> original_number;
guess = rand() % 100 + 1;
++tries;
do {
srand(time(0));
if (guess > original_number)
{
cout << guess << endl;
cout << "Too high!\n\n";
do {
srand(time(0));
guess = rand() % 100 + 1;
} while (guess < original_number);
++tries;
}
if(guess < original_number)
{
cout << guess << endl;
cout << "Too low! \n\n";
do {
srand(time(0));
guess = rand() % 100 + 1;;
} while (guess > original_number);
++tries;
}
} while (guess != original_number );
cout << "The computer guessed your number in " << tries << endl;
return 0;
}