News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Need Heelp Again

Started by DD Games, December 31, 2009, 07:17:07 PM

Previous topic - Next topic

DD Games

If you guys read my post already you guys know that I am making a simple text game that will hopefully sharpen my skills on programming. In my game you are given a algebra problem and you have to solve it. I decided that the game would be better if i set up an array to hold all 25 problems in the game and i plan to make the numbers random each time. Like the first problem of the game will be lets say 1 + A = 3 but if you run the game again the first problem will change into 3 + A = 6. I need help trying to put this all into code. I know it sounds confusing so if you dont get it then ask me for more detals.

kevin

#1
  The solution is fairly straight forward,  all we need are two arrays.  One array for the problems and another for the answers.   Which is what the example bellow does.


#include "input"

Dim Answers(2)
Dim Problems$(2)


; Stores the problem #1 with answer
Problems$(1) = "3+A=10"
  Answers(1) = 7
 
; Stores the problem #2 with answer
Problems$(2) = "A-1=10"
  Answers(2) = 10


NumberOfQuestions=2

Score=0

; run through the questions
for Question =1 to NumberOfQuestions

; Query this problem to the user
print "Problem:"+Problems$(Question)

; get user input
i$=StaticInput("A=")

               ; Check if answer the user gave, is correct or not
if Answers(Question)=val(i$)
print "Correct!"
Score=Score+1
else
ink rgb(255,0,0)
print " Incorrect"
ink rgb(255,255,255)
endif
Sync

next

ink rgb(255,0,0)
print "Game Over"
print "You got "+str$(score)+" out of "+Str$(NumberOfQuestions)+" questions correct"
Sync
FlushKeys
Waitkey


 Moreover, this question seems the natural progression of the first thread,  so in future,  it'd be better if you'd ask all related questions in the same thread.  




DD Games

I am going to give it a try and sorry about the posting a new thread I didnt realize that I needed help again.

DD Games

thanks for clearing up how to use the two arrays so how do you randomize the numbers. i understand how to set a random number i just dont understand how to print it all together with the two integers and the letter A (Example: 1+A=3). Do you understand what im trying to say?

kevin

QuoteDo you understand what im trying to say?

not really..

DD Games

i want to randomize the numbers in each problem. something like rndInt + A = Answer. so that i can make as many problems as i want and  dont have to come up with my own numbers and answers for them.

Let me put it simple-
each problem and it's numbers are made up randomly.

kevin



ValueRange=100

A=Rnd(ValueRange)
B=Rnd(ValueRange)

C= A+B

print str$(A)+"+B="+str$(c)

Sync
waitkey




DD Games

ok thats what I was trying to figure out. I tried writing that code into the problem array but i keep getting errors.