Hey everyone,
So far learning and programming Visual Basic has been a challenge for me but I am continuing to push forward! I need help with my code for "Cook College" and how to make it work since with the current code it is not working as it should.
I am using the Microsoft Visual Basic Reloaded: Fourth Edition for VB. The program I need to make is on page 373 in chapter 6.
The program wants: Create an application that displays the total credit hours and GPA for a student during one semester. Use the following names for the solution, project, and form file: Cook solution, cook project, and Main Form.vb. Save the solution in the VBReloaded2010/Chap06 folder. You can create either your own interface or the one shown in figure 6-72. The figure, which shows a sample run of the application, uses three labels for the output: one for the total credit hours, one for the GPA, and one for the number of grades entered. When the user clicks the Enter Data button, two input boxes should appear in succession: one for the number of credit hours (such as 3) and the next for the corresponding letter grade (such as A). One credit hour of A is worth 4 grade points, an hour of B is worth 3 grade points, and so on. The Enter Data button's click event procedure should allow the user to enter as many sets of credit hours and grades as desired. The labels on the form should be updated after the user enters the letter grade. (The sample output shown in figure 6-72 is a result of the user entering 3 as the credit hours, A as the grade, 5 as the credit hours, and B as the grade.)
This is the code I have so far:
' Project name: Cook Project
' Created by/Modified: <name> on 4/8/2013
' Project purpose: User enters numberofcredits and grade earned for a course.
'Enter lettergrade : That is enter A,B,C,D for grade earned
'Your code should calculate the gpa earned by the formula
' gpa = totalcredits/total grade points average
'Use a while loop to ask for number of credits and grade till the user enters empty string
Option Explicit Off
Option Strict Off
Option Infer Off
Public Class enterButton
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub creditLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles creditLabel.Click
End Sub
Private Sub dataButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dataButton.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
I know there must be something wrong with the code but I cannot see what it may be. I thought getting feedback on it from this wonderful community would help me figure out the issue(s) and hopefully apply a fix to the program that should make it work as it should.
Thank you in advance for any help and feedback any of you can provide.
Best,
So far learning and programming Visual Basic has been a challenge for me but I am continuing to push forward! I need help with my code for "Cook College" and how to make it work since with the current code it is not working as it should.
I am using the Microsoft Visual Basic Reloaded: Fourth Edition for VB. The program I need to make is on page 373 in chapter 6.
The program wants: Create an application that displays the total credit hours and GPA for a student during one semester. Use the following names for the solution, project, and form file: Cook solution, cook project, and Main Form.vb. Save the solution in the VBReloaded2010/Chap06 folder. You can create either your own interface or the one shown in figure 6-72. The figure, which shows a sample run of the application, uses three labels for the output: one for the total credit hours, one for the GPA, and one for the number of grades entered. When the user clicks the Enter Data button, two input boxes should appear in succession: one for the number of credit hours (such as 3) and the next for the corresponding letter grade (such as A). One credit hour of A is worth 4 grade points, an hour of B is worth 3 grade points, and so on. The Enter Data button's click event procedure should allow the user to enter as many sets of credit hours and grades as desired. The labels on the form should be updated after the user enters the letter grade. (The sample output shown in figure 6-72 is a result of the user entering 3 as the credit hours, A as the grade, 5 as the credit hours, and B as the grade.)
This is the code I have so far:
Quote:
' Project name: Cook Project
' Created by/Modified: <name> on 4/8/2013
' Project purpose: User enters numberofcredits and grade earned for a course.
'Enter lettergrade : That is enter A,B,C,D for grade earned
'Your code should calculate the gpa earned by the formula
' gpa = totalcredits/total grade points average
'Use a while loop to ask for number of credits and grade till the user enters empty string
Option Explicit Off
Option Strict Off
Option Infer Off
Public Class enterButton
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub creditLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles creditLabel.Click
End Sub
Private Sub dataButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dataButton.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
Thank you in advance for any help and feedback any of you can provide.
Best,