Sunday, August 2, 2009

Computer Programming C++ Help!?

I need this program to be done in c++ using , ifelse(if applies), dowhile (if applies), while (if applies), for (if applies) statements;





"Write a program that plays a guessing game where the computer tries to guess a number picked by the user. The program asks the user to think of a secret number, and then asks the user a sequence of guesses. After each guess, the user must report if it is too high or too low or correct. The program should count the guesses. (Hint: Maintain HighestPossible and LowestPossible variables, and always guess midway between the two. This is called a binary search.) The program output should look similar to:





Think of a number between 1 and 100 and press any key.


Is the number 50 (Correct, Low, High)? _h_


Is the number 25 (Correct, Low, High)? _h_


Is the number 13 (Correct, Low, High)? _l_


Is the number 19 (Correct, Low, High)? _c_


Number of guesses: 4


"





Underlined material is user input

Computer Programming C++ Help!?
if guess = h then


try = nexttry


nexttry = (try + low)/2


low = try


elseif guess = l then


try = nexttry


nexttry = (try + high)/2


high = try


else


"I know your secret number!"


end if
Reply:Try to work it yourself, it's easy. Use for loop first and nested if...else statements inside it. Work on an algorithm first, then try yourself. If you are stuck after TRYING HARD, then ask for help.
Reply:Are you asking us to write your C++ program for you???

ovary

No comments:

Post a Comment