I am trying to make what I thought was a simple game.
Here's what it is the user inputs a number and the computer tries to guess the number. This is done by means of less or more using the inputbox. function.

This is what I have so far:-

procedure TForm1.StartClick(Sender: TObject);
Var a,b,d:string;
begin
a:=InputBox('User Input','Please enter number between 0 and 100','0');
User.Caption:='User Inputs ' + a;
randomize;
b:=IntToStr(random(100));
Comp.Caption:='Computer Guesses ' + b;
if b<>a then
Res.Caption:='Wrong';
if b > a then
d:=Inputbox('User Input','Is it less or more?','less');
if b=a then
Res.Caption:='Right'

end;

end.

but I am, at a lost as how to take the string of the inputbox and tell the computer it is less more so as it can add or subtract from is original guess until it gets it right.

Any help would be much appericated.
Thanks.

this part sounds strange to me:

Comp.Caption:='Computer Guesses ' + b;
if b<>a then
Res.Caption:='Wrong';
if b > a then
d:=Inputbox('User Input','Is it less or more?','less');
if b=a then
Res.Caption:='Right'

surely the computer's guess can either be correct, lower or higher.

if a = b then
  //snip
else if a > b then
  //snip
else if a < b then
  //snip

however as you know if its lower or higher why ask the user? To get user input for this making a form with 'higher'/'lower' buttons on it may be the best solution

plus it may be worth keeping a note of the closest high and low incorrect guesses; then you can work within the range so guessing the number doesnt take all day :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.