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

I need to create a program to determine a student\'s GPA. The user should enter

ID: 3543635 • Letter: I

Question

I need to create a program to determine a student's GPA. The user should enter the grade (A, B, C, D, or F) and the number of credit hours for a course, and then click on the Record This Course button. The user should then repeat this process for all their courses. After all the course have been recorded, the user should click on the Calculate GPA button. A function procedure should be used to calculate the quality points for a course.



    Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click

        Dim Credits As Double

        Dim CumulativeGPA As Double

        Dim coursegrade As Double


        CumulativeGPA += CourseGrade

        CourseGrade = CDbl(txtCredits.Text)

        Credits += CDbl(txtCredits.Text)



        If txtGrade.Text = "A" Then

            CumulativeGPA += (4 * txtCredits.Text)

        End If


        If txtGrade.Text = "B" Then

            CumulativeGPA += (3 * txtCredits.Text)

        End If


        If txtGrade.Text = "C" Then

            CumulativeGPA += (2 * txtCredits.Text)

        End If


        If txtGrade.Text = "D" Then

            CumulativeGPA += (1 * txtCredits.Text)

        End If


        If txtGrade.Text = "F" Then

            CumulativeGPA += (0 * txtCredits.Text)

        End If


        txtCredits.Clear()

        txtGrade.Clear()

        txtGrade.Focus()


    End Sub


    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        Dim Credits As Double

        Dim CumulativeGPA As Double



        Dim totalGPA As Double = CumulativeGPA / Credits

        txtTotalGPA.Text = CStr((totalGPA))

    End Sub


End Class

Explanation / Answer

HI ,


Since you have already defined CourseGrade as CDbl(txtCredits.Text) , you should use CourseGrade instead of writing txtCredits.Text everywhere. This solves your problem :)


It is also much more efficient because if you need to change the value , you can change at one location (near CourseGrade definition) instead of several places throught the program.


Hope it helps :)



Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click


Dim Credits As Double


Dim CumulativeGPA As Double


Dim coursegrade As Double




CumulativeGPA += CourseGrade


CourseGrade = CDbl(txtCredits.Text)


Credits += CDbl(txtCredits.Text)






If txtGrade.Text = "A" Then


CumulativeGPA += (4 * CourseGrade)


End If




If txtGrade.Text = "B" Then


CumulativeGPA += (3 * CourseGrade)


End If




If txtGrade.Text = "C" Then


CumulativeGPA += (2 * CourseGrade)


End If




If txtGrade.Text = "D" Then


CumulativeGPA += (1 * CourseGrade)


End If




If txtGrade.Text = "F" Then


CumulativeGPA += (0 * CourseGrade)


End If




txtCredits.Clear()


txtGrade.Clear()


txtGrade.Focus()




End Sub




Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click


Dim Credits As Double


Dim CumulativeGPA As Double






Dim totalGPA As Double = CumulativeGPA / Credits


txtTotalGPA.Text = CStr((totalGPA))


End Sub




End Class

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