So I wrote a program for a guess my number game in which I try to guess a number that the computer chooses from 1-100. Now my question is how do I change the code in which me and the computer switch places. So the computer trys to guess a number that I choose.
Here's the code.
cout<<"Think of a number!"<<endl;
int guess =0;
cout<<"Is your number: "<< guess<<endl << "Y/N"<<endl;
cin << answer;
if (char == 'Y') keepGoing=false;
cout<<"Is your number higher?"<<endl<<"Y/N"<<endl;
cin << higherAnswer;
guess=5; // always guesses 5
cout<<"Yay, I got the answer!"<<endl;
*Disclaimer: Code has not been proofread, do not assume is correct*
Now, if you actually read the program, you will see that it always guesses that the answer is 5. The interesting part is how to get the computer to guess something. There's a number of methods that can be used to do this, the simplest methods being to guess a random number, or to just go through all the numbers in order.