Main Menu

Help Needed - Input / Algebra

Started by DD Games, December 31, 2009, 04:24:08 PM

Previous topic - Next topic

DD Games

Hello my name is Dale and I am making a simple text game. I am making this game so i can understand more about arrays, math, input from the user, random numbers, etc. In the game you are given a algebra problem such as this 3 + B = 5 then you have to solve for be by typing in the answer which would be 2 and pushing enter. Once you push enter you will either get it right and be awarded 10 points or you lose 5 points by getting it wrong. I dont know how to let the user type in the answer then award the user 10 points if he gets it right or take away 5 points if he gets it wrong. Help is appreciated :)

kevin

 First, we'll look at getting input from the user....



; tel PB to include the extra Input commands
#include "input"

; This function gets input from the user.. It halts the program until the user hits ENTER
StuffYouTypedin$=StaticInput(">")


; draw what you typed to the screen
print StuffYouTypedin$

;  tell PB to show the screen to the user
Sync

; Now, we'll wait until there's no key existing presses,  because the program is likely to  execute much faster than the person can take their hand off the enter key (from when they typed stuff in)... Which would make the program fall out and end before we can read what we typed..
;  Try removing this line and see what effect it has..
waitnokey

; wait until a key is pressed . 
waitkey





DD Games

I understand input from the user, i just need to know how to award the user 10 points if he gets it right or take away 5 points if he gets it wrong.

kevin

#3

If what the user inputs is the correct value, then add something to the players score variable..


 Score=Score+10



if the input isn't correct, loop back force the user to input another answer

DD Games

but what if the user types an incorrect answer how will the program know if its incorrect.

kevin

 By plugging the value into an   IF / THEN  or  IF / ENDIF statement...

ie,


    if  5=(3 + B )
         print "B is correct"
    else
         print "Nope, B isn't correct"
    endif


DD Games

This is what i have so far:
Sorry I dont know how to do a code box thing like you can.

#Include "Input"

Print "Welcome to Algebra 101"
Name$=StaticInput("What is your name? ")
Cls Rgb (0,0,0)
WaitNoKey

Print "Hello" + " " + Name$
Continue$=StaticInput("Press Enter to continue...")
Cls Rgb (0,0,0)

Print "Instructions:"
Print "1. First we will give you a problem to solve"
Print "2. Then you type in your answer and push enter"
Print "3. If you get it right you get 10 points"
Print "4. If you get it wrong you lose 5 points"
Continue$=StaticInput("Press Enter to start the game...")
Cls Rgb (0,0,0)

Score = 0

Print "First Problem:"
Print "1 + A = 3"
Answer$=StaticInput("A = ")
WaitNoKey


Sync
WaitKey

kevin

#7
  This sample,  gets the input from the user and plugs it into the math expression.


PlayBASIC Code: [Select]
; tel PB to include the extra Input commands
#include "input"

; repeat this section, until the until expression is true
repeat

; This function gets input from the user.. It halts the program until the user hits ENTER
StuffYouTypedin$=StaticInput(">")

; Does 5 =(2+variable) ?
if 5=(2+val(StuffYouTypedIn$))

; yes, so say so on the screen
print StuffYouTypedin$ +" is correct!"

print "Well done!"

; set the variable to exit the REPEAT/UJNTIL
CorrectAnswerFound=true

else

; nope the expression in the IF statement wasn't true, so the stuff
; the person typed in was wrong
print StuffYouTypedin$ +" is way wrong...."
endif

; tell PB to show the screen to the user
Sync

; loop this section of code, UNTIL the variable CorrectAnswerFound ='s true
until CorrectAnswerFound=true



; clear the keyboard buffer
flushkeys

; wait until a key is pressed .
waitkey



 
 


DD Games

in this game the user has to find out what the letter equals. Example:
1 + A = 5
A = 4

kevin


DD Games


DD Games

I got it to work :). Thanks alot it works like a champ.