Главная страница Случайная страница КАТЕГОРИИ: АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника |
Math TestThis program helps students test their math addition skills. It allows a user to choose upper limits for each of the 2 numbers in the math test questions, then repeatedly displays random addition questions with booth addends within 0 and the limit range. The " format$" and " replace$" functions are used to display neatly formatted questions, and a total count of correct and incorrect answers is tallied. ! First, use the " input" function to request upper limit numbers from the.! user. Save the response in the variables " l1" and " l2". Notice that! there are no " $" characters in these variables, because they are meant! to hold numeric values: input " High limit of the first number", l1input " High limit of the second number", l2! These next two variables are used to count the number of correct and! incorrect answers entered by the user. The count for both is initially! set to zero: c = 0i = 0! Label this point in the program to jump back later: start:! Next, generate 2 random numbers. The rnd() function generates a number! between 0 and 1. That's multiplied by an upper limit number (entered! earlier by the user), and then rounded to the nearest whole number,! using the round() function. Notice that the entire " rnd() * l1"! expression is treated as the argument for the round() function. The! results are stored in the variables " n1" and " n2": n1 = round(rnd() * l1) n2 = round(rnd() * l2)! Because the rounded number above is a decimal number, we need to convert! it to a string, to be concatenated and displayed to the user in the form! of a question. We could use the str$() function, but that would display! each number with a decimal point and a trailing 0 (i.e. " 7.0"). To make! the display a little nicer, we'll use the format$() function to display! up to 5 characters, with no trailing decimal characters. Save the! result in the variable n1$ (notice the use of the " $" character, because! this variable holds a string): n1$ = format$(" #####", n1)! Trim any trailing spaces from the second number, using the replace$()! function. Save the result in the variable n2$: n2$ = replace$(format$(" #####", n2), " ", " ")! Concatenate the numbers above into a nicely formatted question, and use! the input function to request an answer from the user. Save the user's! response in the variable " answer". input n1$ + " + " + n2$ + " = ", answer! If the user's answer is correct (the total of n1 + n2), add 1 to the! count of correct answers (stored in the numeric variable " c"), and! display a positive message to the user. If the answer is incorrect,! incorrect the counter variable that holds the number of incorrect! answers (" i"), and display the appropriate message: if answer = n1 + n2 c = c + 1 popup " CORRECT! ", 0, 0, 0 else i = i + 1 popup " Incorrect", 0, 0, 0 endif! Wait 2 seconds for the user to see the message: pause 2000! Go back the to " start" label and do the question routine all again: goto start! If at any point the back button is clicked duing an input operation, an! error is raised, and the program automatically jumps to the label marked! " OnError": OnError:! When the OnError event occurs, display a message that concatenates the! total number of correct and incorrect answers (you could use the! format$() function here to display these numbers without trailing! decimal characters, if desired): popup str$(c) + " correct, " + str$(i) + " incorrect.", 0, 0, 0Here's the whole program, without comments: input " High limit of the first number", l1input " High limit of the second number", l2c = 0i = 0start: n1 = round(rnd() * l1) n2 = round(rnd() * l2) n1$ = format$(" #####", n1) n2$ = replace$(format$(" #####", n2), " ", " ") input n1$ + " + " + n2$ + " = ", answer if answer = n1 + n2 c = c + 1 popup " CORRECT! ", 0, 0, 0 else i = i + 1 popup " Incorrect", 0, 0, 0 endif pause 2000goto startOnError: popup str$(c) + " correct, " + str$(i) + " incorrect.", 0, 0, 0Данная страница нарушает авторские права? |