Sunday, August 2, 2009

I need help with this c++ program?

#include %26lt;conio.h%26gt;// needed for getch


#include %26lt;iostream.h%26gt;//needed for cout message





void startup();


void method();


int main()


{


startup();


method();








getch();


return 0;


}


void startup()


{


cout%26lt;%26lt;"safi khan"%26lt;%26lt;'\n';


cout%26lt;%26lt;"november 16, 2007"%26lt;%26lt;'\n';


cout%26lt;%26lt;"pg e"%26lt;%26lt;'\n';


cout%26lt;%26lt;""%26lt;%26lt;'\n';


}


void method()


{


int minimum = 0, maximum = 100, guess, press, press2;


cout%26lt;%26lt;"Think of a number."%26lt;%26lt;'\n';


cout%26lt;%26lt;"If done press 1: ";


cin%26gt;%26gt;press;





if (press = 1)


{


while (press2 == 3)


{


guess = maximum - minimum/2;


cout%26lt;%26lt; "Is this your guess "%26lt;%26lt;guess%26lt;%26lt;'\n';


cout%26lt;%26lt;"press 1) if too high press 2) if too low press 3) if i'm right press 4) to quit";


cin%26gt;%26gt;press;





if(press2 == 1)


{


maximum = guess, guess = (maximum - minimum) / 2;


continue;


}


if(press2 ==1)


{


minimum = guess, guess = (maximum - minimum) / 2;


continue;


}


if(press2 == 3)


{


cout%26lt;%26lt;"I'm correct. Game over.";


break;


}


if(press2 ==4)


{


cout%26lt;%26lt; "Game over";


break;


}





}


}


}

I need help with this c++ program?
It does work. The problem is that immediately after that, namely the statement





while (press2 == 3)





You never read anything into press2 nor do you initialize it to anything so it will never be 3. Consequently you exit out of the while loop and the enclosing if statement.


No comments:

Post a Comment