For loops?

Blitz3D Forums/Blitz3D Beginners Area/For loops?

po(Posted 2004) [#1]
Every math class I have, we always do a 10 minute division drill. Since I am rather slow at it, I thought I would make a program to help me out, but I am having troubles with for loops. On the drill, there is a grid of 90 squares, and on the left most colum, the teacher puts random numbers from 100 to 999. On the top colum he puts random numbers between 1 and 9. You divide the first small number by the first big number, and then you divide the first small number by the 2nd big number etc... The teacher told us that it would be easier to put a "." instead of a little "r" to signify a remainder.
Here is the code I have so far:
AppTitle "Math Drill"

;num_1=10/3
;r=10 Mod 3
;Print num_1+"."+r
;WaitKey()

Graphics 800,600

font1=LoadFont("Arial",26,True,False)

SetBuffer BackBuffer()

SeedRnd MilliSecs()

.start

Time% = MilliSecs() + 600000

num_x=218
num_y2=218
;big_numbers=Rnd(100,999)

While Not KeyHit(1)

Color 220,220,0
Rect 209,13,390,298,1

Color 0,0,0
Rect 214,18,380,288
For x=216 To 590	Step 42
	
	For y=20 To 280	Step 26
	
		Color 220,220,0
		Rect x,y,40,24,1
	
	Next
Next

Color 0,0,0
Oval 233,23,5,5,1
Rect 221,30,31,2,1
Oval 233,34,5,5,1

For big_numbers_for=1 To 10

	big_numbers=Rnd(100,999)
	
Next 

For num_y=46 To 300 Step 26
	
	Color 0,0,0
	Text num_x,num_y,big_numbers
		
Next

;For small_numbers=1 To 10

;small_numbers=Rnd(1,9)
	
;Next 

;For num_x2=218 To 300 Step 40
;	
;	Color 255,0,0
;	Text num_x2,num_y2,small_numbers
;		
;Next	
 


SetFont font1
Color 255,0,0
Text 347,565,"Time: "+((Time-MilliSecs())/1000)
If MilliSecs() > Time Then Goto time_up


Flip
Cls

Wend 

.time_up
End

If I put the small numbers in, the screen goes black and I can't exit. Why is that? The big_numbers keeps on repeating in the while loop why is that?


cermit(Posted 2004) [#2]
This little loop makes it impossible
for the program to quit.

For small_numbers=1 To 10

small_numbers=Rnd(1,9)

Next 


this is an evil loop that never ends.
you better change the rnd ( or loop
variable ) if you want this program
to work.

Btw nice games on your homepage, sea-shoot was
pretty cool and it has nice graphics too =)


soja(Posted 2004) [#3]
Bob the Blob runs WAAAY to fast to play on my machine!


po(Posted 2004) [#4]
Btw nice games on your homepage, sea-shoot was
pretty cool and it has nice graphics too =)

Thanks!
Bob the Blob runs WAAAY to fast to play on my machine!

It was? That's not good! How do you make it so that the speed is the same on all computers?


cermit(Posted 2004) [#5]
Yeah i hate when that happens to games, my cousins
computer does that all the time when it run 2d games.

Btw her is my "Math Drill" feel
free to change the source.

All@ bet you cant be better
than "Not Good.." hehe


; Title

AppTitle "Math Drill"


; Graphics Mode

Graphics 640, 480, 16, 2

SetBuffer BackBuffer()


; Super Randomize

SeedRnd MilliSecs()


; Small Number Dim

Dim number_s(8)

For x = 0 To 8

number_s(x) = Rnd( 1, 9 )

Next


; Big Number Dim

Dim number_b(8)

For x = 0 To 8

number_b(x) = Rnd( 100, 999 )

Next


; Anserw Type

Type ans

Field a.ans, ans_a
Field ans_x, ans_y, ans_c

End Type



; Start

.start


; Set Right Anserws To Zero

Global righta = 0

Global marker_x = 0, marker_y = 0

Global finished = False, count_answers = False

Global time = 600, time_r = MilliSecs()


; Delete All Previous Anservs

For a.ans = Each ans

Delete a

Next


; Create Anserw Types

For x = 0 To 8

For y = 0 To 8

a.ans = New ans
a\ans_x = x * 33 + 204
a\ans_y = y * 17 + 174
a\ans_a$ = 0
a\ans_c = 0

Next

Next


; Program Lol

While KeyHit(1) = False


; Time

If MilliSecs() > time_r + 1000 Then

If time > 0 Then time = time - 1

time_r = MilliSecs()

EndIf


; Time Up !

If time < 1 Then

finished = True

EndIf



; Get ASCII

key = GetKey()


; Number True

If key > 47 And key < 58 Then

For a.ans = Each ans

If ( a\ans_x - 204 ) / 33 = marker_x And ( a\ans_y - 174 ) / 17 = marker_y Then

If Len( a\ans_a$ ) < 4 Then a\ans_a$ = a\ans_a + Chr$( key )

EndIf

Next

EndIf


; Bakspace True

If key = 8 Then

For a.ans = Each ans

If ( a\ans_x - 204 ) / 33 = marker_x And ( a\ans_y - 174 ) / 17 = marker_y Then

a\ans_a$ = Left$( a\ans_a$, Len( a\ans_a$ ) - 1 )

EndIf

Next

EndIf


; Enter True

If KeyHit(28) Then

For a.ans = Each ans

If ( a\ans_x - 204 ) / 33 = marker_x And ( a\ans_y - 174 ) / 17 = marker_y Then

If number_b( marker_y ) / number_s( marker_x ) = a\ans_a$ Then

a\ans_c = 1

marker_y = marker_y + 1

If marker_y > 8 Then marker_y = 0 : marker_x = marker_x + 1

If marker_x = 9 Then finished = True

Goto q

Else

a\ans_c = 2

marker_y = marker_y + 1

If marker_y > 8 Then marker_y = 0 : marker_x = marker_x + 1

If marker_x = 9 Then finished = True

Goto q

EndIf

EndIf

Next

EndIf

.q



; Clear Screen

Cls


; Draw Board

Color 0, 255, 0

Text 320, 64, "* Math Drill *", 1

Color 255, 0, 0

Rect 154, 154, 33 * 10 + 1, 17 * 10 + 1, 1

Gosub drawboard


; Draw Small Numbers

For x = 0 To 8

Color 0, 0, 0

Text x * 33 + 204, 157, number_s(x), 1

Next


; Draw Big Numbers

For y = 0 To 8

Color 0, 0, 0

Text 171, y * 17 + 174, number_b(y), 1

Next

; Cheat Switch

If key = 99 Then If cheat = True Then cheat = False : key = 0

If key = 99 Then If cheat = False Then cheat = True : key = 0


; Cheat By Pressing [ C ]

If cheat = True Then

For a.ans = Each ans

If ( a\ans_x - 204 ) / 33 = marker_x And ( a\ans_y - 174 ) / 17 = marker_y Then

Color 0, 255, 0

Text 320, 90, number_b( marker_y ) / number_s( marker_x ), 1

EndIf

Next

EndIf


; Draw Marker

Color 0, 0, 255

If marker_x < 9 Then Rect marker_x * 33 + 187, marker_y * 17 + 171, 34, 18, 0


; Draw Anserw Types

For a.ans = Each ans

If a\ans_c = 0 Then Color 0, 0, 255

If a\ans_c = 1 Then Color 0, 255, 0

If a\ans_c = 2 Then Color 255, 0, 0

Text a\ans_x, a\ans_y, a\ans_a, 1

Next


; Draw Time Left

Color 255, 0, 0

Text 320, 380, "Time Left " + time + " ( Sec ) ", 1


; Display Results

If finished = True Then

If count_answers = False

For a.ans = Each ans

If a\ans_c = 1 Then righta = righta + 1

Next

EndIf

count_answers = True

Text 320, 400, righta + " Right Anserw Of 81", 1

If righta < 21 Then Text 320, 420, " Very Bad ! ", 1

If righta > 20 And righta < 41 Then Text 320, 420, " Not Good.. ", 1

If righta > 40 And righta < 61 Then Text 320, 420, " Better Practice More ", 1

If righta > 60 And righta < 81 Then Text 320, 420, " Greate Work ", 1

If righta = 81 Then Text 320, 420, " Master Mind ! ", 1

Text 320, 440, " Try Again ? Y/N ", 1

If key = 121 Then Goto start

If key = 110 Then Goto endp

EndIf


; Of Course I Gotta Sign This =)

Text 320, 460, "By Cermit =)", 1


; Flip Buffer

Flip


; Program End

Wend

.endp

End


; Draw Board

.drawboard

For x = 0 To 9

For y = 0 To 9

Color 255, 128, 0

Rect x * 33 + 155, y * 17 + 155, 32, 16, 1

Next

Next

Return



You can see the right answer by pressing "c"
Cheating is not good i know but i just wanted
to see that my math did work =)

I hate when they do these 10 minutes tests
in school so i didnt try it serious myself =)
We'll say i got "Master Mind !" ( i didnt cheat
i promise *ironic* )


po(Posted 2004) [#6]
Wow, I wouldn't change a thing! Except that something is wrong in your ans type, I think. When the time ran out, my right answers went up and up and didn't stop. I don't know anything about types so I don't know. :)

The FPS thing works, but now it is verrry slow and laggy.


cermit(Posted 2004) [#7]
Right i didnt fix the timer thing yet but i will
fix it know.. Okey its fixed now =) i updated
the code above.

Yeah fps at 30 is very slow but try more like 60 or 50
then it should run faster.


po(Posted 2004) [#8]
How do you type in the remainder?


cermit(Posted 2004) [#9]
Oh thats the weak thing about it.
You cant because i didnt have the
strenght to do that.. so the computer
just chops everyting off after the .

18.84 becomes 18 and so on..


po(Posted 2004) [#10]
Have you tried MOD?
a=372
b=5
Print a/b+"."+a Mod b
WaitKey()



cermit(Posted 2004) [#11]
Do you have msn messenger ? It would be simpler
than the forum. Can download it from http://messenger.msn.com/


po(Posted 2004) [#12]
Yes, I have msn. it's p0ser_5@... a zero beside the p)


Beaker(Posted 2004) [#13]
Any 13 year old who has an A-Team van on their website gets my vote. po for president! :)


cermit(Posted 2004) [#14]
Yeah! po for president!


po(Posted 2004) [#15]
Hehe.