Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have my code written, which followed this basic outline (http://www.chegg.com/

ID: 3548852 • Letter: I

Question

I have my code written, which followed this basic outline (http://www.chegg.com/homework-help/starting-out-with-visual-basic-2010-5th-edition-chapter-5-problem-7pc-solution-9780136113409), however I have errors that I can't seem to solve.


Private Sub btnEntData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEntData.Click
        Dim strname As String  'To hold the name
        Dim Score1 As String 'To hold score1 name
        Dim Score2 As String 'To hold score2 name
        Dim Score3 As String 'To hold score3 name
        Dim avg As String    'To hold avg name
        'Getting input
        strName = InputBox("Enter Student's Name:", "Input Needed")
        Score1 = InputBox("Enter a Test Score1:", "Input Needed")
        Score2 = InputBox("Enter a Test Score2:", "Input Needed")
        Score3 = InputBox("Enter a Test Score3:", "Input Needed")
        'Calculate average
        avg = (Score1 + Score2 + Score3) / 3

        'Calculate grade and display the result.
        If avg > 90 Then
            lstDisplay.Items.Add(strname + "    " + "Average:" + avg.ToString() + "     " + "Grade:" + "    " + "A")
        ElseIf avg >= 80 Then
            lstDisplay.Items.Add(strname + "    " + "Average:" + avg.ToString() + "     " + "Grade:" + "    " + "B")
        ElseIf avg >= 70 Then
            lstDisplay.Items.Add(strname + "    " + "Average:" + avg.ToString() + "     " + "Grade:" + "    " + "C")
        ElseIf avg >= 60 Then
            lstDisplay.Items.Add(strname + "    " + "Average:" + avg.ToString() + "     " + "Grade:" + "    " + "D")
        ElseIf
            lstDisplay.Items.Add(strname + "    " + "Average:" + avg.ToString() + "     " + "Grade:" + "    " + "F")
        End If
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'Close the form
        Me.Close()
    End Sub




My errors are as follows:

Option Strict On disallows implicit conversions from 'String' to 'Double'.


I have changed Strict to Off and the errors remain. Any help is greatly appreciated.



Explanation / Answer

The error shows becoz score1, score2 and score3 are all string and you are finding sum of string and dividing it by integer. Try converting string to integer and then find sum like this. Tell me if it doesnot work

avg = (Convert.ToDecimal(Score1) + Convert.ToDecimal(Score2) + Convert.ToDecimal(Score3)) / 3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote