Well, I see that I did not really solve my problem. It now longer trys to use the bigg numbers, and it always finds the number it is supposted to in the end. Some times it is realy fast, but other times it has to guess a rediculus amount of times.
I think this is what is cousing the problem, but I dont know why
Code:
{
randNo = rand();
compNo = (randNo % compNo) + 1;
//cout <<compNo << "CompNo is biggest" << endl;
}
The whole "program"
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int myRandNo;
int compNo = 50;
int randNo = 0;
int tryes = 0;
char gameRep = 'y';
cout << "Welcome to the guessing game" << endl;
cout << "Please enter a number between 1 and 100: ";
cin >> myRandNo;
while (gameRep =='y')
{
while (compNo != myRandNo)
{
//seed the rand
srand(time(0));
//guess was to low
if (compNo < myRandNo)
{
randNo = rand();
compNo = (randNo % 100) + compNo;
//cout << compNo << "CompNo is smallest" << endl;
}
//guess was to high
if (compNo > myRandNo)
{
randNo = rand();
compNo = (randNo % compNo) + 1;
//cout <<compNo << "CompNo is biggest" << endl;
}
tryes++;
}
//cout << "\nThe computer guessed you number after " ;
cout << tryes << " attempts" << endl;
cout << "Would you like to play again? (y/n)";
cin >> gameRep;
}
system("pause");
return 0;
}