Decimal points

BlitzPlus Forums/BlitzPlus Programming/Decimal points

schilcote(Posted 2008) [#1]
I'm writing a program which tests a student on math. The problem is, whenever it asks a division question, the correct answer is rounded, which is a behavior I don't want. How do I stop this?

student_name$=Input$("Hi! What is your name? ")
Print "Hello "+student_name+"!"
Print "Please wait..."

SeedRnd MilliSecs()
Delay (Rand(1000,10000))

Print "Okay "+student_name+", now we will begin testing."
Print "I'm going to test you on using rational numbers."
x=Input("How many questions? ")

For t=0 To x

num_a=Rand(1,100)
num_b=Rand(1,100)
operator=Rand(1,4)

Select operator

Case 1
op$="+"
corans#=num_a+num_b

Case 2
op$="-"
corans#=num_a-num_b

Case 3
op$="*"
corans#=num_a*num_b

Case 4
op$="/"
corans#=num_a/num_b

End Select

ans=Input("What is "+num_a+""+op$+""+num_b+" ?")

If ans=corans# Then
	Print corans#+" is correct!"
	answers_correct=answers_correct+1
Else
	Print "Incorrect. The answer is "+corans#
	answers_incorrect=answers_incorrect+1
EndIf

Next

Print "Out of "+t+" questions, you got "+answers_correct+" questions correct, and "+answers_incorrect+" questions incorrect."
score#=answers_correct/t
Print "Therefore, your score is "+score#+"."

WaitKey
End




schilcote(Posted 2008) [#2]
Never mind, figured it out. You have to have all the variables that result in the float you want to be floats as well. Kind of a dumb rule, but easy to work around.


Sauer(Posted 2008) [#3]
Actually you'll find that integer division can be useful in some situations, but a lot of people feel the same way you do about it. The next version of Python is supposed to get rid of integer division, but integer division is one of those things that I value in BlitzPlus and the current edition of Python.


andy_mc(Posted 2008) [#4]
integer division is useful for things like tile based games. You can simply divide the x coord of the object by the tilesize to get it's tile coord.


schilcote(Posted 2008) [#5]
I'll remember that.