Visual Basic question: Computers are playing an increasing role in education. Wr
ID: 3559751 • Letter: V
Question
Visual Basic question: Computers are playing an increasing role in education. Write a program that will help an elementary school student learn multiplication. Use random object to produce two positive one-digit integers.The program should then prompt the user with a question such as How much is 6 x 7?. The student then inputs the answer. Next the program checkes the students answer. If it is correct, display the message "Very Good" and ask another multiplication problem. If the answer is wrong, display the message "No, Please Try again" and let the student try the same question repeatedly until the student gets it right. A separate function should be used to generate each new question. This function should be called once when the application begins execution and each time the user answers correctly.
Explanation / Answer
Create five variables (e.g. intNumber1, intNumber2, intAnswer, intAnswer, intAsked) that are part of the entire form:
VB Code:
In the form_load insert the code:
VB Code:
intNumber2 = int(rnd*10 + 1)
lblQuestion.caption = "How much is " & intNumber1 & " times "_ & intNumber2 & "?"
intAnswer = intNumber1 * intNumber2
intAsked = intAsked + 1
You now have the first question prepared. Now in your next question command button, insert the code:
VB Code:
dim intComment as integer
if cint(txtAnswerStudentGave.text) = intAnswer then
intComment = int(rnd * 4 + 1)
intScore = intScore + 1
if intComment <= 1 then
lblComment.caption = "Very Good"
elseif intComment = 2 then
lblComment.caption = "Excellent"
elseif intComment = 3 then
lblComment.caption = "Good Job"
else
lblComment.caption = "Keep up the good work"
end if
else
intComment = int(rnd * 3 + 1)
if intComment <= 1 then
lblComment.caption = "No, please try again"
elseif intComment = 2 then
lblComment.caption = "Wrong, try once more"
else
lblComment.caption = "Don't Give Up!"
end if
end if
if intAsked < 10 then
intNumber1 = int(rnd*10 + 1) 'Maxium of 10
intNumber2 = int(rnd*10 + 1)
lblQuestion.caption = "How much is " & intNumber1 & " times "_
& intNumber2 & "?"
intAnswer = intNumber1 * intNumber2
intAsked = intAsked + 1
else
intScore = round(intScore / 10)
lblComment.caption = "Your score is " & intscore & "%." & vbcrlf & "--Copied from VBForums.com"
end if
I accept no responsibility for errors! Errors will probably form if you modify the above code in any way!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.