Its getting late here and im starting to get irritated a bit from this,so i think imma take a long relaxing sleep first, and continue messing with this tomorrow again, but for now, this is what i did,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int tries = 0,uNum,rNum,max,min;
cout << " Enter the number you want PC to guess(1-100): " << endl;
cin >> uNum;
srand(time(0));
rNum=rand() % 100 + 1;
do
{
rNum;
++tries;
cout << " Computer Guessed " << rNum << endl;
if(rNum > uNum)
cout << " Computer Guessed too High!" << endl;
rNum = rNum - 1;
if(rNum < uNum)
cout << "Computer Guessed too Low!" << endl;
rNum = rNum + 1;
}while(rNum != uNum);
cout << "Computer guessed your number in " << tries << " tries!" << endl;
return 0;
}
|
i did this before the do loop,thinking, that it means the rNum gets randomly generated,but stays that way.
1 2
|
srand(time(0));
rNum=rand() % 100 + 1;
|
than in the do loop i call that rNum and, if rNum > than uNum i set this
rNum = rNum - 1;
thinking, it means the rNum would change from the current guess,to -1 in value , meaning it wouldnt guess that number again,it will just go -1 every time the rNum > uNum . Same for the if rNum < uNum i set it so that rNum increases to +1 ,thinking that each time the rNum is called, and if rNum < uNum it would just start increasing by +1 , not lower anymore . . . now, for tonight,i would just simply be satisfied to know, that those codes i wrote ,are really what i think they are.
I really do appreciate your help,and i hope you can bare with me for a little longer till i figure this out, it means a lot me to successfully figure this out, it would motivate me even further to learn and mess around with C++ , which i really really want to learn. Good Night for now fellas:)