It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

GPA Calculator Code Help

Moderator: dafunkymunky

GPA Calculator Code Help

Postby hammerfd5 on Thu Apr 21, 2011 3:55 am

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.

This is my code. Yes, I realize that it doesn't work at all and that there are for sure many mistakes. I also don't have a function procedure like I need.

Specifically, I have not been able to get a handle of how to add up the grade values, and course hours cumulatively.
I'm completely lost. Any help would be very much appreciated =)

Public Class Form1
Dim Credits As Double
Dim CumulativeGPA As Double

Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click
CumulativeGPA += CourseGrade()
CourseGrade =
Credits += CDbl(txtCredits.Text)

If txtGrade.Text = "A" Then
CumulativeGPA += 4
End If

If txtGrade.Text = "B" Then
CumulativeGPA += 3
End If

If txtGrade.Text = "C" Then
CumulativeGPA += 2
End If

If txtGrade.Text = "D" Then
CumulativeGPA += 1
End If

If txtGrade.Text = "F" Then
CumulativeGPA += 0
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 totalGPA As Double = CumulativeGPA / Credits
txtTotalGPA.Text = CStr((totalGPA))

End Sub
End Class
hammerfd5
 
Posts: 1
Joined: Thu Apr 21, 2011 3:52 am

Re: GPA Calculator Code Help

Postby sanjon on Thu Apr 28, 2011 9:07 pm

First of all, sorry for the late reply. I went through all the late posts and saw this unanswered question.

I see that you have actually made an effort and tried to code the program so I will do my best to help you. I will try to take your code and adjust it to make it work. I will also add comments to make it easier for you to understand. And if you have any questions after that, just let me know. So here is the code:

Code: Select all
Public Class Form1
'QPoints stand for Quality Points
Dim QPoints As Double
Dim hours As Integer

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

'Select Case is an easy way to check for multiple conditions and gets rid of the many If-Else statements...

hours += txtCredits.Text

Select Case txtGrade.Text
Case "A"
QPoints += (4 * txtCredits.Text)
Case "B"
QPoints += (3 * txtCredits.Text)
Case "C"
QPoints += (2 * txtCredits.Text)
Case "D"
QPoints += (1 * txtCredits.Text)
Case "F"
'You don't really need to add anything here but I am just being consistent...
QPoints += (0 * txtCredits.Text)
End Select

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 totalGPA As Double = QPoints / hours
txtTotalGPA.Text = CStr((totalGPA))

End Sub
End Class
sanjon
 
Posts: 40
Joined: Sun Dec 05, 2010 6:20 pm


Who is online

Users browsing this forum: No registered users and 3 guests