Question
Open the SwatTheBugs Solution (SwatTheBugs Solution.sln) file contained in the ClearlyVB2012Chap17SwatTheBugs Solution folder. Open the Code Editor window and study the existing code. Start and
Open the SwatTheBugs Solution (SwatTheBugs Solution.sln) file contained in the ClearlyVB2012\Chap17\SwatTheBugs Solution folder. Open the Code Editor window and study the existing code. Start and then test the application. Notice that the application is not working correctly. Stop the application. Locate and correct the errors in the code. Save the solution and then start and test the application again. Close the Code Editor window and then close the solution.
The problem in the code I found is when I enter 10 as dividend and 2 as the divisor, the result says: 10 divided by 2 is 0.2 . ---What are the errors in the code?
Here is the code:
Public Class frmMain
Private Function GetQuotient(ByVal decN1 As Decimal, ByVal decN2 As Decimal) As Decimal ' return the quotient after dividing decN1 by decN2
Dim decQ As Decimal
If decN2 0 Then decQ = decN1 / decN2 End If Return decQ End Function
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Me.Close() End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click ' display the quotient
Dim strDividend As String Dim strDivisor As String Dim decDividend As Decimal Dim decDivisor As Decimal Dim decQuotient As Decimal
strDividend = InputBox("Enter the dividend:", "SwatTheBugs") strDivisor = InputBox("Enter the divisor:", "SwatTheBugs")
Decimal.TryParse(strDividend, decDividend) Decimal.TryParse(strDivisor, decDivisor) decQuotient = GetQuotient(decDivisor, decDividend) lblQuotient.Text = decDividend.ToString & " divided by " & decDivisor.ToString & " is " & decQuotient.ToString End Sub End Class
frmMain.vb frmMain.vb [Design] n X Start Page SwatTheBugs Calculate Quotient Exit SwatTheBugs Calculate Quotient Exit
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