I cannot get the math right for the higher option. When you run the program, the program will go lower, but it wont go go higher. What is it i need to change? this program is due by the end of my class today and i can't figure it out.
//Project 8.4. Guesses the number the user enters between 1-100.
#include <iostream>
using namespace std;
int UsersNum, YesNo, HighLow, Re_Use;
int n = 50, lastguess;
int HigherThan = 0, LowerThan =101;
int main ()
{
cout << "Welcome to the number guessing game! \n";
cout << "I will try and guess the number you will enter. \n";
cout << "Please enter a number between 1 - 100. \n";
cin >> UsersNum;
cout << "Is your number 50? Enter 1 for Yes or enter 2 for No. \n";
cin >> YesNo;
if (YesNo == 1){
cout << "I have guessed your number correctly. Thanks for playing. \n";
return 0;}
do
{
if (YesNo == 2){
cout << "Higher or lower? \n";
cout << "Enter 1 for higher or enter 2 for lower. \n";
cin >> HighLow;}
switch (HighLow)
{ case 1:
n = (LowerThan - n) / 2 + n;
//LowerThan = lastguess;
cout << "Is this your number " <<n<< " ? \n";
cout << "Please enter 1 for yes or 2 for no. \n";
cin >> Re_Use;
break;
case 2:
n = (n - HigherThan) / 2 + HigherThan;
//HigherThan = lastguess;
cout << "Is this your number " <<n<< " ? \n";
cout << "Please enter 1 for yes or 2 for no. \n";
cin >> Re_Use;
break;
default:
cout << "Invalid Entry. \n";
break;
}
if (Re_Use == 1)
cout << "I have guessed your number correctly! Thanks for playing. \n" ;
}
while (Re_Use == 2);
return 0;
}