Ok, I have had a hard time trying to understand this next evolution for programming in VB Net. I successfully completed a Mortgage Calculator
last week and thought, hey maybe I can do this programming. So went to the next chapter and understood some of it but I am having a few issues.
First of all for the instructions below on creating the coding below, I understand how on the first 3 I understand how to do.
BUt for the loop, I understand I will have to have a outer loop and inner loop, such as a FOR NEXT outside loop and a IF ELSE END for the inner.
So for calculating the averages seems ok to do, but the issue I have is for the bullet listing number 7 and 8.
I can't figure out how to code the program to get it to keep the averages and a running total.
Could someone help me out.

Create a VB.NET program that calculates class averages. It must include the following features:
• Use Option Strict On
• Have the user enter the number of students in the class
• Create a FOR NEXT loop that will start at 1 and go through the number of students entered
• Inside the loop:
Use an InputBox to get a score on an exam for a student
Add the value of the score to the running total
Display the running average
• Calculate an average score for the class
• Display the average
• After the number of students has been processed allow the user to click on New Class. This will allow the average to be calculated for a new class.
• However, keep a running average for all students in all classes and a running average for the classes.
• Uses standard naming conventions for objects and variables

Suggestion: Use an array to store the class details, and loop through the array to perform the calculations of Average and Total

When using the array, would be it be good to use the array to store the running averages for the students and then use that same array for the class averages, or do I need to setup an additional array to compensate for that?

Either way. I find multiple arrays sometimes easier, but you could even use one array, and make it two or 3 dimensional. Remember an array acts much like a "virtual" spreadsheet!

Ok here is what I got, but I can't get the calculation of adding the classes and the averages in the totals section boxes.
Private Sub CalcBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcBtn.Click
Dim NumStuTxtBx As Integer
Dim _NOS As Integer 'Number of Students'
Dim _NumOfClasses As Integer 'Number of additional classes'
Dim GrandTotal As Integer
Dim Grades As Double = 0
Dim Computed_Grades As Double = 0
Try
NumStuTxtBx = Integer.Parse(Me.NumStuTxtBx.Text)
_NOS += NumStuTxtBx
CalcBtn.Enabled = False
For a As Integer = 1 To NumStuTxtBx
Grades = CDbl(InputBox("Enter Grades of Students Exams"))
GrandTotal += Grades
Computed_Grades += Grades
AvgTxtBx.Text = CStr(Computed_Grades / _NOS)
AvgStuClsTxtBx.Text = CStr(GrandTotal / _NOS)
Next
NewClsBtn.Enabled = True
Catch ex As Exception
MsgBox("How Many Students are there in this Class?", MsgBoxStyle.OKOnly)
Me.NumStuTxtBx.Text = ""
Me.NumStuTxtBx.Focus()
Return
End Try
Me.NumStuTxtBx.Text = ""
Me.NumStuTxtBx.Focus()
AvgAllClsTxtBx.Text = CStr(GrandTotal / _NumOfClasses)
Return
End Sub

Private Sub NewClsBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewClsBtn.Click
Dim _NOS As Integer 'Number of Students'
Dim _NumOfClasses As Integer 'Number of additional classes'
Dim GrandTotal As Integer
CalcBtn.Enabled = True
NewClsBtn.Enabled = False
_NumOfClasses += 1
NumClsTxtBx.Text = CStr(_NumOfClasses)
AvgAllClsTxtBx.Text = CStr(GrandTotal + _NumOfClasses)
AvgStuClsTxtBx.Text = CStr(GrandTotal / _NOS)
NumStuTxtBx.Text = ""
NumStuTxtBx.Focus()

End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.