Hello forum.I am truly sorry this is my first post,but as I am a terrible programmer who has just begun(or might I say,just 'properly' started) C++.I am have a problem with my 'guess my number'game where a 'computer' has to guess the numbers.But I seem to have a problem on my application.
using namespace std;
int number_guess = rand() % 100 + 1; // lets say I chose a random number between 1 and 100.
int tries = 0;
cout << "choose a number between 1 and 100 and I'll guess it." << endl;
cout << "is " << number_guess << " your number?(y/n)" << endl;
++tries; // calculates how many tries it took the computer
cin >> answer;
if (answer == 'y')
cout << "Whoa,I did it in " << tries << " shot(s)! I deserve a pat on the hardware!" << endl;
} while (answer == 'n'); // continue until the computer is wrong.
Now,this is designed so that I secretly pick the number between 1 and 100,then computer has to guess it.I tell the computer if he is wrong or right(y/n) then computer either continues guessing,or he congratulates himself.
Here is the problem.
The computer,is guessing the EXACT same number each time.So what I mean by that is,actually,I'll give you an example.
lets say my computer guess 12 and he is wrong.
Next turn,he guessess 12 AGAIN.Or should I say,
HE GUESSESS THE SAME NUMBER OVER AND OVER AND OVER.
This seem to be my fault,and because I am a beginner,I can't seem to find a problem.Please help forum users.Thank you in advance.