Having a small problem. I had the code working before but I either don't see the problem in plain site or I'm not understanding something. Basically, within the new AGK2 Activities on Activity 6.4 I made some changes to the Guess program just to mess around and see things work. I understand what If statements are and how they keep going down the line until they hit EndIf terminating that If statement. I started using ElseIf with my If to make the code a bit cleaner and either screwed something up in the process or left something additional out. Hopefully someone can spot my error:
// Project: Guess
// Created: 2015-04-17
// set window properties
SetWindowTitle( "Guess" )
SetWindowSize( 768, 1024, 0 )
SetDisplayAspect( 768.0/1024)
#include "Buttons.agc" // Including the Buttons file for use
ClearScreen()
SetUpButtons() // Display the buttons
number = Random(0,9)
PrintC("Guess what my number is(0-9):")
Sync()
Sleep(2000)
//***Keep repeating until correct***
Repeat
// Take the button value pressed and store it
guess = GetButtonEntry()
While guess < 0 or guess > 9
Print("Your guess must be between 0 and 9")
Print("Enter your guess again(0 - 9) : ")
Sync()
Sleep(2000)
guess = GetButtonEntry()
EndWhile
diff = guess - number
If diff > 2
message$ =" Way To high"
ElseIf diff > 0
message$ = "Slightly too high"
ElseIf diff < -2
message$ = "Way to low!"
Elseif diff < 0
message$ = "Slightly too low!"
EndIf
Sync()
Sleep(2000)
Until guess = number
Do
//***Display the number the computer chose***
Printc("My number was: ")
Print(number)
Print(message$)
Sync()
Loop
So the above code is the Guess activity modified over the course of the chapters. When I run the program, the statements within the If statements only run part of the time. Sometimes it will tell me I was "Way too High!"(Or to low, etc.) sometimes it won't then doesn't let me input to try again. The goal was to add a Repeat...Until statement but that isn't working for me. Am I missing something obvious or not comprehending If statements like I thought I was?