CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Help please!

  1. #1
    Join Date
    Dec 2012
    Posts
    1

    Help please!

    Hey guys, I have to create a console application for an assignment that will allow members of staff to record and analyse student grades. The system should allow staff members to:

    • Enter student names and their grade
    • Identify the student with the highest grade
    • Identify the student with the lowest grade
    • Identify the average grade
    • Review a list of all students and their grades



    The application is a fixed class size of SIX students at this stage. The solution you develop MUST show the use of more than two modular elements, a control structure and the use of a conditional command.

    I complete noob at programming and honestly don't know whether I'm on the right lines with what I've coded so far. So far the problems I'm encountering are as follows:

    It let's me enter names and grades continuously and won't let me return to the menu until I hit 'Enter' twice' with out imputing a name or grade.

    It won't 'display all students', when I select the option in the menu after I get out of the of the continuous loop in 'Add a student'

    Finally, there is something wrong with it calculating the minimum, maximum and average grade, I don't know why though.

    Sorry for the messy code guys it's my first application, I would be grateful if you's could point me in the right direction to get this working.

    Code:
    Imports System.Math
    Module Module1
    Dim strStudent(6) As String
    Dim strGrade(6) As Integer
    Dim intCounter As Integer
    Dim cnt As Integer
    
    Sub Main()
    StudentDetails()
    End Sub
    Public Sub StudentDetails()
    
    'variables
    Dim intmenuchoice As Integer = 0
    
    Console.ForegroundColor = ConsoleColor.DarkMagenta
    System.Console.WriteLine(" ##### ")
    System.Console.WriteLine(" # # ##### ## ##### ###### #### ")
    System.Console.WriteLine(" # # # # # # # # # ")
    System.Console.WriteLine(" # #### # # # # # # ##### #### ")
    System.Console.WriteLine(" # # ##### ###### # # # # ")
    System.Console.WriteLine(" # # # # # # # # # # # ")
    System.Console.WriteLine(" ##### # # # # ##### ###### #### ")
    System.Console.WriteLine(" ")
    
    'menu
    Do
    Console.ForegroundColor = ConsoleColor.White
    System.Console.WriteLine("****************************")
    System.Console.WriteLine("1) Add a student")
    System.Console.WriteLine("2) display all students")
    System.Console.WriteLine("3) Min, Max and average grade")
    System.Console.WriteLine("4) Exit")
    System.Console.WriteLine("select an option (1-4): ")
    System.Console.WriteLine("****************************")
    intmenuchoice = System.Console.ReadLine()
    ' selection code
    If intmenuchoice < 1 Then
    System.Console.WriteLine("invalid input")
    ElseIf intmenuchoice = 1 Then
    acceptinformation()
    'system.console.writeline("option 1 selected: Add a student ")
    
    'system.console.writeline("option 2 selected: display all students")
    
    ElseIf intmenuchoice = 2 Then
    displayinformation()
    
    
    'system.console.writeline("option 2 selected: display Min, max and average")
    
    ElseIf intmenuchoice = 3 Then
    Console.ForegroundColor = ConsoleColor.Red
    System.Console.WriteLine("Student Average Grade = " & Round(averageGrade(), 2))
    System.Console.WriteLine("Student Min Grade = " & Round(minGrade(), 2))
    System.Console.WriteLine("Student Max Grade = " & Round(MaxGrade(), 2))
    
    'Exit program
    ElseIf intmenuchoice = 4 Then
    System.Console.WriteLine("option 4 selected: Exit")
    Else
    System.Console.WriteLine("invaild input")
    End If
    
    Loop While (intmenuchoice <> 4)
    
    'pause screen
    System.Console.WriteLine("press return to exit")
    System.Console.ReadLine()
    End Sub
    Public Sub acceptinformation()
    Try
    Do
    
    intCounter = intCounter + 1
    System.Console.WriteLine("Enter Students name: ")
    strStudent(intCounter) = System.Console.ReadLine()
    System.Console.WriteLine("Enter students Grade: ")
    strGrade(intCounter) = System.Console.ReadLine()
    If (strGrade(intCounter) < 0 Or strGrade(intCounter) > 100) And (strGrade(intCounter) <> -100) Then
    
    intCounter = intCounter - 1
    End If
    Loop While strGrade(intCounter) <> -100
    
    Catch ex As Exception
    Console.WriteLine("Error: Invalid Grade, Please enter any value ! " & vbLf & ex.Message)
    End Try
    End Sub
    
    Public Sub displayinformation()
    
    Dim intloopcounter As Integer
    For intloopcounter = 1 To intloopcounter - 1
    Console.ForegroundColor = ConsoleColor.Green
    System.Console.WriteLine("Student detials")
    System.Console.WriteLine("********************************************")
    System.Console.WriteLine("Student Name :" & strStudent(intloopcounter))
    System.Console.WriteLine("Grade :" & strGrade(intloopcounter))
    Next
    End Sub
    
    Function averageGrade()
    Dim total, avg As Double
    Dim cnt As Integer
    For cnt = 1 To intCounter - 1
    total = total + strGrade(cnt)
    
    Next
    avg = total / (intCounter - 1)
    Return avg
    End Function
    
    Function minGrade()
    Dim min As Integer
    Dim cnt As Integer
    
    min = strGrade(1)
    For cnt = 2 To intCounter - 1
    If strGrade(cnt) < min Then
    min = strGrade(cnt)
    End If
    Next
    Return min
    End Function
    
    Function MaxGrade()
    Dim max As Integer
    Dim cnt As Integer
    
    max = strGrade(1)
    For cnt = 2 To intCounter - 1
    If strGrade(cnt) Then
    max = strGrade(cnt)
    End If
    Next
    Return max
    End Function
    End Module

  2. #2
    Join Date
    Jul 2012
    Posts
    46

    Re: Help please!

    rayox,

    Nobody wants to read through all of the code to solve a list of vague questions. If you could ask for HELP in learning about one of the issues I'm sure that one of these fine Gurus would be more than willing to help. Since it is for a course it is a learning process so ask specific questions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured