c++

Associate
Joined
29 May 2012
Posts
862
Location
UK
On behalf of a mate

Private Sub cmddisplay_Click()
Cls
Dim Name As String
Dim Assignment1 As Integer
Dim Assignment2 As Integer
Dim Exam As Integer
Dim DateOfBirth As Date
Dim age As Integer
Dim C As Byte
Dim AverageMark As Single
Dim Percentage As Integer
Dim Grade As String
Dim accumulator As Single
Dim BestStudent As String
Dim BestMark As Integer
Dim C_Percentage As Single
' Define output variable Field names


Open App.Path & "\Results2.DAT" For Input As #5 'this opens the DAT file

Print
Print Tab(1); "Name"; Tab(20); "A1 Mark"; Tab(32); "A2 Mark"; Tab(42); "Exam"; Tab(52); "DOB"; Tab(65); "(%)Mark"; Tab(75); "Grade"; Tab(91); "Age";
Do Until EOF(5)
Let C = C + 1
Input #5, Name, Assignment1, Assignment2, Exam, DateOfBirth

Let Percentage = (Assignment1 + Assignment2 + Exam) / 3
' Gives grade to each student
If Percentage >= 80 Then
Let Grade = "D"
End If

If Percentage >= 65 And Percentage < 80 Then
Let Grade = "M"
End If

If Percentage >= 50 And Percenatage < 65 Then
Let Grade = "P"
End If

If Percentage < 50 Then
Let Grade = "U"
End If

Let mark(C) = Percentage
Let student(C) = Name
If BestMark < mark(C) Then ' If statement to calculate best student
Let BestMark = mark(C)
Let BestStudent = student(C)
End If

Let age = Int(((Date - DateOfBirth) / 365))
Print Tab(4); Name; Tab(25); Assignment1; Tab(32); Assignment2; Tab(42); Exam; Tab(52); DateOfBirth; Tab(65); Percentage; Tab(75); Grade; Tab(91); age;

Let C_Percentage = C_Percentage + Percentage

Loop
Close #5
' calculates average percentage of total marks of all students
Let AverageMark = Int(C_Percentage / C)
Print Tab(37); "_____________________"
Print Tab(37); "Average Mark =" & Format$(Format$(AverageMark, "Standard"), "@@@@")

Print
Print AverageMark

lblBestResult.FontSize = 12
lblBestResult.ForeColor = vbRed
lblBestResult.Caption = "Best Student is " & BestStudent & " with a score of" & BestMark & "%"



End Sub
Private Sub lblBestResult_Clic()
End
End Sub




Private Sub cmdlogout_Click()
Me.Hide
Form1.Show
End Sub

Private Sub Form_Load()

is not working, its not caculatin the grade and its keep screw up! HELP!!
 
Soldato
Joined
20 Dec 2004
Posts
16,027
Been ages since I've had the horror of working with VB....but it looks like you're performing integer division in the average calculation. Make sure you're working with floats.
 
Don
Joined
19 May 2012
Posts
17,645
Location
Spalding, Lincolnshire
Looks like VB6 - albeit some really odd VB (e.g. you don't need to use "Let" when setting variables)

Some of the code is missing e.g. the array declarations for "mark()" and "subject()"

Without seeing the contents of the "results2.dat" file, it's hard to say what the issue is.


If this was real world code, the data types could be simplified to just Integers and Doubles (but if this is "schoolwork", then they will need to stay as is)
 
Soldato
Joined
20 Dec 2004
Posts
16,027
Just to clarify....in VB this line will perform integer division

Percentage = (Assignment1 + Assignment2 + Exam) / 3

This will perform floating point division :

Percentage = (Assignment1 + Assignment2 + Exam) / 3.0

You'll need to look up the difference yourself.
 
Don
Joined
19 May 2012
Posts
17,645
Location
Spalding, Lincolnshire
Just to clarify....in VB this line will perform integer division

Percentage = (Assignment1 + Assignment2 + Exam) / 3

This will perform floating point division :

Percentage = (Assignment1 + Assignment2 + Exam) / 3.0

You'll need to look up the difference yourself.


That makes no difference and is incorrect

Results from VB6 that I have open at work at the minute:

Code:
?(1+1.5+2.2)/3
 1.56666666666667 
?(1+1.5+2.2)/3.0
 1.56666666666667


His division will work fine, although he should explicitly cast the result into his integer percentage e.g.

Percentage = CInt((Assignment1 + Assignment2 + Exam) / 3)


Although that assumes you want to round the result e.g

Code:
?cint((1+1.5+2.2)/3)
 2 
?int((1+1.5+2.2)/3)
 1 
?fix((1+1.5+2.2)/3)
 1
 
Back
Top Bottom