Restart the program after users input.
Hello I am stuck in the last part of this program. When the user press y, the program would have to run from beginning. It actually does but gives me some crazy number. Try running the code below. Thanks. #include <iostream> using namespace std; int midpoint; int y = 100; int x = 1; char check; char tryagain; int main(){ do{ cout<<"Think about a number between 1 and 100."; midpoint = ( x + y ) / 2; while(x != y){ cout<<endl <<"Is it"<< " "<< midpoint << " "<< "?"; cin>>check; if(check=='l' || check=='L') { y = midpoint; midpoint = ( x + y ) / 2; } else if(check=='h' || check=='H') { x = midpoint; midpoint = ( x + y ) /2; } else if( check == 'c' || check == 'C') { break; } else{ cout<<"Incorrect choice."<<endl; } } cout<< "Great! Do you want to try again? (y/n)"; cin >> tryagain; }while (tryagain == 'y'); return 0; }