Question
I am looking for the code for starting out with visual basic 7e chapter 5 programming challenge 7. The solution listed in the solutions section
I am looking for the code for starting out with visual basic 7e chapter 5 programming challenge 7.
The solution listed in the "solutions" section is coming out incorrect every time and I cannot find the error. Does anyone have the correct code for this?
https://www.chegg.com/homework-help/Starting-Out-With-Visual-Basic-7th-edition-chapter-5-problem-7PC-solution-9780134400150
The challenge:
Create an application that uses random integers to test the user's knowledge of arithmetic. Let the user choose from addition, subtraction, multiplication, and division. The integers used in the problem should range from 20 to 120. When giving feedback, use color to differentiate between a correct answer response, versus an incorrect answer response. Also check for non-integer input. Preparing division probelms require special consideration because the quotient must be an integer. Therefore, you can use a loop to generate new random values for the second operand until you find one that divides the first operand evenly. Use the MOD operator to verify the integer division remainder is zero.
My problem, the color "feedback" always states incorrect saying the answer should be 0, I need to know how to make the answer display true to the given operation.
What is on my screen currently (I keep changing things..)
Public Class Form1 Private Sub btnCheck_Click(sender As Object, e As EventArgs) Handles btnCheck.Click Dim answer As Integer Dim userAnswer As Integer = 0
If Integer.TryParse(txtAnswer.Text, userAnswer) Then 'Check answer & assign color to feedback If answer = userAnswer Then lblFeedback.ForeColor = Color.Green lblFeedback.Text = "Correct answer!" Else lblFeedback.ForeColor = Color.Red lblFeedback.Text = "Sorry, the answer should have been " & answer.ToString End If Else lblFeedback.ForeColor = Color.Red lblFeedback.Text = "Please enter a valid integer" End If
End Sub
Private Sub btnNext_Cbtlick(sender As Object, e As EventArgs) Handles btnNext.Click 'Variable for random integers Const maxrange As Integer = 100 Const minval As Integer = 20 Dim rand As New Random Dim answer As Integer Dim userAnswer As Integer
txtAnswer.Clear() lblFeedback.Text = "" Dim op1 As Integer = rand.Next(maxrange) + minval Dim op2 As Integer = rand.Next(maxrange) + minval
'Answer for addition If radAddition.Checked Then lblProblem.Text = op1.ToString & " + " & op2.ToString & " = " answer = op1 + op2
'Answer for subtraction ElseIf radSubtraction.Checked Then lblProblem.Text = op1.ToString & " = " & op2.ToString & " = " answer = op1 - op2
'Answer for multiplication ElseIf radMultiplication.Checked Then 'Adjust the sizes op1 = op1 \ 2 op2 = op2 \ 2 lblProblem.Text = op1.ToString & " * " & op2.ToString & " = " answer = op1 * op2
'Answer for division ElseIf radDivision.Checked Then 'adjust so the quotient is always even Do op2 = rand.Next(50) + 1 Loop Until op1 Mod op2 = 0 And op2 < op1 lblProblem.Text = op1.ToString & " / " & op2.ToString & " = " answer = op1 \ op2 End If End Sub
Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
End Sub End Class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started