|
-
Nov 12th, 2014, 06:49 PM
#1
Thread Starter
Junior Member
Help! Display numbers and grade from tests for each person.
I got these errors on my program and I need help fixing them.

Directions:
NOTE: Student First Name + a space + Student Last Name will be 18 characters maximum
Computer Problem:
To write a program, named P08.vb, that has the Program Name and Your Name, as comment lines, at the top of the source code.
The program displays a list of names of all students, their score on each test, their average score (rounded to a whole number), and the letter grade. The grade will depend on the rounded average score as follows:
Average Score Letter Grade
0 - 59 "F"
60 - 69 "D"
70 - 79 "C"
80 - 89 "B"
90 - 100 "A"
Array and Function Requirements:
An array, named Score(), of integers, to read and process five test scores.
A function, named Sum(), which computes and returns the sum of the scores as an integer.
A function, named Average(), which computes and returns the average score, rounded
to an integer.
A function, named Grade(), which computes and returns the letter grade, based on the
average score.
Suggested Header: Function Grade(ByVal averageScore As Integer) As Char
Display Your Name and Assignment# at the top of the output screen.


My code:
' Name: Anna DeAngelis
' Program: p08.vb
Imports System.IO
Imports RahimLibrary
Module P07
Const AUTHOR As String = "Anna DeAngelis Assignment 8"
'-------------------- Subroutine: Main()---------------------------------
Sub Main()
Dim Tokens As StringTokenizer
Dim Delimiter As Char() = {" ", ",", ";", ":"}
Dim Diskfile As String = "P08.DAT"
Dim Name As String
Dim k, scoreSum, avgScore As Integer
Dim Grade As Char
Console.WriteLine(vbNewLine & AUTHOR)
If Not File.Exists(Diskfile) Then
Console.WriteLine("File: " & Diskfile & " does not exist")
Utility.BlankLine(2) : Exit Sub : End If
FileOpen(1, Diskfile, OpenMode.Input)
While Not EOF(1)
Tokens = New StringTokenizer(LineInput(1), Delimiter)
Name = Tokens.NextToken() & " " & Tokens.NextToken()
Name = Name.PadRight(13)
Console.Write(vbNewLine & Name)
For k = 0 To 4
Score(k) = Tokens.NextToken()
Console.Write(Format(Score(k), "0").PadLeft(4))
Next
ScoreSum = Sum(Score)
avgScore = Average(ScoreSum, 5)
Console.WriteLine(" Average =" & Format(avgScore, "0").PadLeft(4))
End While
FileClose(1)
End Sub ' Main()
'-------------------- Function: Sum()---------------------------------
Function Sum(ByVal P As Integer()) As Integer
Dim scoreSum = 0, k As Integer
For k = 0 To P.GetUpperBound(0) : scoreSum += P(k) : Next
Return scoreSum
End Function 'Sum()
'-------------------- Function: Average() --------------------------------
Function Average(ByVal scoreSum As Integer, _
ByVal count As Integer) As Integer
Dim averageScore As Double
averageScore = scoreSum/count
averageScore = Utility.Round(averageScore, 0)
Return Convert.ToInt32(averageScore)
End Function 'Average()
'-------------------- Function: Grade() --------------------------------
Function Grade (ByVal Grade As Char, _
ByVal Score As Integer) As Char
If (Score < 60) Then : Console.WriteLine("F")
ElseIf (Score 60 To 69) Then : Console.WriteLine("D")
ElseIf (Score 70 To 79) Then : Console.WriteLine("C")
ElseIf (Score 80 To 89) Then : Console.WriteLine("B")
ElseIf (Score 90 To 100) Then : Console.WriteLine("A")
End If
Return Grade
End Function 'Grade()
End Module 'P08
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|