Hi again,
I am creating a very simple educational game for my assignment and i need help with getting sums to be answered correctly and incorrectly and then progressing to the next sum.
This is the code which doesnt work and i would like to know how to make sum able to be answered and then progress or finish the game:
FUNCTION themaingame:
WHILE TRUE
PRINT "START THE GAME HERE", 100, 100
LOCAL answer%
PRINT "2+1=",100,150
INPUT value%
IF value% = 3
IF value% = >3
IF value% = < 3
SHOWSCREEN
WEND
ENDFUNCTION
Any help will be appreciated, thanks
DARMAKWOLF TO THE RESCUE!
see attached project.
Let me explain my code.
SETCURRENTDIR("Media")
SETTRANSPARENCY RGB(255,0,255)
LOADFONT "edufont.png",0
SETFONT 0
WHILE TRUE
LOCAL num1% //Defines a number
LOCAL num2% //Defines another number
LOCAL answer% //Holds our answer
STATIC numcorrect% = 0 //Holds how many we have correct
num1 = RND(25) //Generate a random number between 0 and 25 for our first number
num2 = RND(25) //Generate a random number between 0 and 25 for our second number
redo: //This is a label. You can use GOTO to hop back to here in code.
PRINT "Welcome to Sums! " + numcorrect + " correct so far.",5,5 //Print our welcome message with the number we have completed
PRINT num1 + " + " + num2 + " = ",5,35 //Displays our problem to solve. As you can see, it calls variables num1 and num2
INPUT answer,160,35 //This is the simple INPUT command to draw user input.
IF INTEGER(num1 + num2) = answer //This IF statement checks whether or not num1+num2 = answer
CLEARSCREEN //Clears the screen
PRINT "CORRECT!",5,5 //Prints CORRECT!
INC numcorrect,1 //Increase correct problems by 1
SHOWSCREEN //Draw the screen
SLEEP 2000 //Freezes the screen for 2 seconds
ELSE //ELSE... means the user failed the question. num1 + num2 is not answer.
CLEARSCREEN //Clears the screen
PRINT "SORRY! TRY AGAIN!",5,5 //Prints SORRY! TRY AGAIN!
SHOWSCREEN //Draw the screen
SLEEP 2000 //Freezes the screen for 2 seconds
GOTO redo //GOTO our redo label we made earlier to retry the question
ENDIF //ENDIF ends the IF statement
SHOWSCREEN
WEND
Thanks DARMAKWOLF :booze:
More than welcome, friend! Ask me if you need any more help!
@Darmakwolf In regards to the above code how do you tell the game to only redo the sums tens times.
Hi Sev, sorry I'm not sure if you want the code only ask 10 times the question?¿... My English it's very poor, too many times :-[ :-[ Sorry.
Well if it's this it's very easy you only have to add a counter...
SETCURRENTDIR("Media")
SETTRANSPARENCY RGB(255,0,255)
LOADFONT "edufont.png",0
SETFONT 0
WHILE TRUE
LOCAL num1% //Defines a number
LOCAL num2% //Defines another number
LOCAL answer% //Holds our answer
STATIC numcorrect% = 0 //Holds how many we have correct
GLOBAL counter_Times=0 //This it's the variable for count how many times the program makes the Question
num1 = RND(25) //Generate a random number between 0 and 25 for our first number
num2 = RND(25) //Generate a random number between 0 and 25 for our second number
redo: //This is a label. You can use GOTO to hop back to here in code.
PRINT "Welcome to Sums! " + numcorrect + " correct so far.",5,5 //Print our welcome message with the number we have completed
PRINT num1 + " + " + num2 + " = ",5,35 //Displays our problem to solve. As you can see, it calls variables num1 and num2
//New COde
if counter_Times<=10
INC counter_Times, 1 //This last parameter 1, don't it's needed it¡s the same -"INC counter_Times" () only when you add 1.
INPUT answer,160,35 //This is the simple INPUT command to draw user input.
ELSE
CLEARSCREEN
PRINT "THE PROGRAM ENDS",0,0
SHOWSCREEN
SLEEP 2500
END
ENDIF
IF INTEGER(num1 + num2) = answer //This IF statement checks whether or not num1+num2 = answer
CLEARSCREEN //Clears the screen
PRINT "CORRECT!",5,5 //Prints CORRECT!
INC numcorrect,1 //Increase correct problems by 1
SHOWSCREEN //Draw the screen
SLEEP 2000 //Freezes the screen for 2 seconds
ELSE //ELSE... means the user failed the question. num1 + num2 is not answer.
CLEARSCREEN //Clears the screen
PRINT "SORRY! TRY AGAIN!",5,5 //Prints SORRY! TRY AGAIN!
SHOWSCREEN //Draw the screen
SLEEP 2000 //Freezes the screen for 2 seconds
GOTO redo //GOTO our redo label we made earlier to retry the question
ENDIF //ENDIF ends the IF statement
SHOWSCREEN
WEND