Code: #include <iostream> #include <time.h> using namespace std; void main() { srand(time(0)); while (true) { int brian; int happy; int r; r = rand () %101; cout <<rand () %101 << "\n"; cout << "enter number \n" ; cin >> brian; if (brian == r) { cout << "Go you, you win\n"; } else if (r<brian){ cout << "Lower\n"; } else { cout << "Higher\n"; } } } Could anyone point out what's wrong with my code . It's meant to be a higher or lower game but it keeps generating a new number everytime?
check the changes and ask what you do not understand. Code: #include <iostream> #include <time.h> using namespace std; [COLOR=Red]int[/COLOR] main() { [COLOR=Red]int brian=-1; int happy; int r=0;[/COLOR] srand(time([COLOR=Red]NULL[/COLOR])); [COLOR=Red]r = rand () %101; //let it outside the loop in order to get 1 value only for each run of the program cout <<r << "\n";[/COLOR] while ([COLOR=Red]brian!=r[/COLOR]) { cout << "enter number:" ; cin >> brian; if (brian == r) { cout << "Go you, you win\n"; } else if (r<brian){ cout << "[COLOR=Red]number x is[/COLOR] Lower\n"; } else { cout << "[COLOR=Red]number x is [/COLOR]Higher\n"; } } getchar();getchar(); }