How I create a Grade Point Average in Visual Basic 2008

Submitted by Jrdnfaith on
' Project name: Cook Project ' Project purpose: User enters numberofcredits and grade earned for a course. 'Enter numericgrade : That is enter 4,3,2,1 for grade earned 'Your code should calculate the gpa earned by the formula ' gpa = totalcredits/totalgradepoints 'Use a while loop to ask for numberofcredits and grade till the user enters empty string Option Explicit Off Option Strict Off Option Infer Off Public Class MainForm Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click Me.Close() End Sub Private Sub enterButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles enterButton.Click ' calculates and displays the total credit hours and GPA Dim creditHourscounter As Integer Dim gradePointscounter As Integer Dim credithours As Integer Dim grades As Integer Dim StringCreditHours As String = String.Empty ' Dim NumericGrade As String Dim creditsAccumulator As Integer Dim gradeAccumulator As Integer Const prompt As String = "Enter number of credit hours" Const title As String = "Credit hours" ' Dim numberOfCredits As Integer Dim numberOfGrades As Double Dim totalCredits As Double Dim totalGradePoints As Double Dim gpa As Double Dim gradenumericValue As String = String.Empty 'StringCreditHours = InputBox("Enter number of credit hours: 4 or 3") 'Write the Do while/until loop to ask for user inputHours till String is empty 'Do Loop ' StringCreditHours = InputBox("Enter number of credit hours") StringCreditHours = InputBox(Prompt, title) Do While StringCreditHours > String.Empty Integer.TryParse(StringCreditHours, credithours) StringCreditHours = InputBox(prompt, title) creditHourscounter = creditHourscounter + 1 creditsAccumulator = creditsAccumulator + credithours Loop totalCredits = creditsAccumulator numberOfGrades = creditsAccumulator gradenumericValue = InputBox("Enter NumericGrade: 4 or 3 or 2 or 1 or 0") Do While gradenumericValue > String.Empty Decimal.TryParse(gradenumericValue, grades) gradenumericValue = InputBox("Enter NumericGrade: 4 or 3 or 2 or 1 or 0") gradePointscounter = gradePointscounter + 1 gradeAccumulator = gradeAccumulator + grades Loop 'Do While gradenumericValue > 0 'gradenumericValue = InputBox("Enter NumericGrade: 4 or 3 or 2 or 1 or 0") 'gradePointscounter = gradePointscounter + 1 'Loop ' NumericGrade = InputBox("Enter NumericGrade: 4 or 3 or 2 or 1 or 0") 'Convert string to Numeric data 'Calculate totalgradepoints and totalcredit hours 'each gradepoints is got by product of numberOfCredits * gradenumericValue totalGradePoints = grades * credithours 'creditHourscounter = creditHourscounter + 1 ' totalGradePoints = gradePointscounter ' totalCredits = gradePointscounter * StringCreditHours ' Loop ' Do While > 5 'Convert string to Numeric data ''StringCreditHours = InputBox("Enter number of credit hours") 'Calculate totalgradepoints and totalcredit hours 'each gradepoints is got by product of numberOfCredits * gradenumericValue ' Integer.TryParse(StringCreditHours, hours) ' Loop 'totalGradePoints = numberOfGrades gpa = totalGradePoints/gradeAccumulator gpaLabel.Text = "GPA: " & gpa numberOfGradesLabel.Text = "Number of grades entered: " _ & numberOfGrades End Sub End Class