#include <iostream>
#include <stdlib.h>
#include <ctime>
#include <string>
usingnamespace std;
int main(){
int number = rand()%100+1;
int guess;
int trys;
string comp_guess;
string answer;
srand(time(0));
cout<<"Type \"computer\" to guess the computers number."<<endl;
cout<<"Type \"user\" to make the computer guess your number."<<endl;
cin>>comp_guess;
if(comp_guess == "computer"){
cout<<"Guess my hidden number"<<endl;
cin>>guess;
for (int i = 0; i < 101; i++){
if (guess == number){
cout<<"CONGRATULATIONS!!! YOU WIN!!!"<<endl;
cout<<"It took you "<<trys + 1<<" trys to guess correctly."<<endl;
break;
}
elseif (guess < number){
cout<<"Too Low"<<endl;
cin>>guess;
trys++;
}
elseif (guess > number){
cout << "Too High"<<endl;
cin>>guess;
trys++;
}
}
}
}
My problem is that i always get 8 as the correct number. Why is this happening????
Type "computer" to guess the computers number.
Type "user" to make the computer guess your number.
computer
Guess my hidden number
8
CONGRATULATIONS!!! YOU WIN!!!
It took you 1 trys to guess correctly.
That doesn't work. this is suppose to be for the bracketing search exercise and i can't get it to select a different number besides 8. i have been at it for more than a day thinking of what to do and i don't know what it is. this is really aggravating can someone please help.
#include <iostream>
#include <stdlib.h>
#include <ctime>
#include <string>
usingnamespace std;
int main(){
int number = rand()%100+1;
int guess;
int control_num = 101;
int control = -1;
int trys;
string comp_guess;
string answer;
string high = "higher";
string low = "lower";
cout<<"Type \"computer\" to guess the computers number."<<endl;
cout<<"Type \"user\" to make the computer guess your number."<<endl;
cin>>comp_guess;
if(comp_guess == "computer"){
srand(time(0));
cout<<"Guess my hidden number"<<endl;
cin>>guess;
for (int i = 0; i < 101; i++){
srand(time(0));
if (guess == number){
cout<<"CONGRATULATIONS!!! YOU WIN!!!"<<endl;
cout<<"It took you "<<trys + 1<<" trys to guess correctly."<<endl;
break;
}
elseif (guess < number){
cout<<"Too Low"<<endl;
cin>>guess;
trys++;
}
elseif (guess > number){
cout << "Too High"<<endl;
cin>>guess;
trys++;
}
}
}
}