-
Apr 9th, 2006, 11:36 PM
#1
Thread Starter
New Member
test scores help
im making a program where I have to use a Inputbox function to repeatedly ask the user to enter a series of test scores from 1-100.
i have to calculate and display the following values:
total of all scores
nubmer of scores that were entered
the average score
and the number of scores in the A range (90-100)
the number of scores in the B range (80-89)
the number of scores in the C range (70-79)
the number of scores in the D range (60-69)
the number of scores in the F range (0-59)
i got everything working except for the number of letter grades displaying in the labels. Do i need to incorporate If statements for each one or use a case structure?
-
Apr 10th, 2006, 12:11 AM
#2
Re: test scores help
You can use either...
VB Code:
If MyScore > somenumber or MyScore < somenumner then ...
'some code
End If
VB Code:
Select Case MyScore
Case SomNumber to SomeOtherNumber
'some code
End Select
-
Apr 10th, 2006, 12:26 AM
#3
Thread Starter
New Member
Re: test scores help
yeah i tried the Select Case but cant figure out what to type in to get the number of scores to appear in the boxes
the total number of scores just keeps appearing in only the A's label
-
Apr 10th, 2006, 12:30 AM
#4
Addicted Member
Re: test scores help
What do you mean by total number of scores? The average of all the scores or The number of scores you entered in?
EDIT: I just re-read the first post and you do say the Total Number of scores entered. My question to you is, Do you have a counter to keep track of the number of scores entered? If so, assign the Value of the Counter to whatever label you're working with. IE:
TotalLabel.text = NumberofRecordsEntered.Tostring()
Using Framework 2.0, VB.Net 2005.
-
Apr 10th, 2006, 05:27 AM
#5
Re: test scores help
Originally Posted by gigemboy
You can use either...
VB Code:
If MyScore > somenumber or MyScore < somenumner then ...
'some code
End If
VB Code:
Select Case MyScore
Case SomNumber to SomeOtherNumber
'some code
End Select
By the way gig, ever seen what Case SomeNumber to SomeOtherNumber compiles to in IL? with integer or char types it simply enumerates all of the integer possibilities from SomeNumber to SomeOtherNumer like:
Case 1: Case 2: case 3: case 4: etc, etc..
anything else it converts to an if anyways
Bill
-
Apr 10th, 2006, 04:23 PM
#6
Thread Starter
New Member
Re: test scores help
Alright I got most of the program working alright with all my message boxes and such, and with my Select Case, it puts the numbers in the correct slot, but it just keeps adding a number on for each test score i enter.....for example. I enter a 70, it will put a 1 in the C's label, I enter a 80, it will enter a 2 in the B's label, i Enter a 90, it will put a 3 in the A's label. Here's my code, its probably a stupid mistake but bare with me, I'm just a poor community college student haha
VB Code:
Dim scorestr As String
Dim score As Integer
Dim count As Integer
Dim total As Integer
Dim average As Single
Dim Acount As Integer
Dim Bcount As Integer
Dim Ccount As Integer
Dim Dcount As Integer
Dim Fcount As Integer
Do Until scorestr = ""
If IsNumeric(scorestr) Then
score = Val(scorestr)
If score >= 0 AndAlso score <= 100 Then
total += score
count += 1
Acount += 1
Bcount += 1
Ccount += 1
Dcount += 1
Fcount += 1
Select Case score
Case 90 To 100
Me.lblAs2.Text = Acount
Case 80 To 89
Me.lblBs2.Text = Bcount
Case 70 To 79
Me.lblCs2.Text = Ccount
Case 60 To 69
Me.lblDs2.Text = Dcount
Case 0 To 59
Me.lblFs2.Text = Fcount
End Select
Me.lblCount2.Text = Format(count)
Me.lblTotal2.Text = Format(total)
Me.lblAverage2.Text = Format(average, "N2")
-
Apr 10th, 2006, 04:28 PM
#7
Re: test scores help
VB Code:
f IsNumeric(scorestr) Then
score = Val(scorestr)
If score >= 0 AndAlso score <= 100 Then
total += score
count += 1
Acount += 1
Bcount += 1
Ccount += 1
Dcount += 1
Fcount += 1
If between zero and one hundred then total = total + score.
Then, you add one to all of the variables, no matter what. Then, later you are using the select to apply that value to the label. I think your problem lies in where you do your math, and when.
INstead of incrementing all of the letter count variables there, they should really only be incrementing when the selct case hits one of their type of grade:
VB Code:
Select Case score
Case 90 To 100
ACount +=1
Me.lblAs2.Text = Acount
Case 80 To 89
BCount+=1
Me.lblBs2.Text = Bcount
Case 70 To 79
Ccount+=1
Me.lblCs2.Text = Ccount
Case 60 To 69
Dcount +=1
Me.lblDs2.Text = Dcount
Case 0 To 59
FCount +=1
Me.lblFs2.Text = Fcount
End Select
You see, there's no reason to increment ALL the count variables every time it loops.
Bill
-
Apr 10th, 2006, 04:29 PM
#8
Re: test scores help
Originally Posted by conipto
By the way gig, ever seen what Case SomeNumber to SomeOtherNumber compiles to in IL? with integer or char types it simply enumerates all of the integer possibilities from SomeNumber to SomeOtherNumer like:
Case 1: Case 2: case 3: case 4: etc, etc..
anything else it converts to an if anyways
Bill
Didnt know that
-
Apr 10th, 2006, 04:42 PM
#9
Thread Starter
New Member
Re: test scores help
When i enter each, they come out correctly now under the select case rather then under the spot before. Rather then entering each and having that number appear after each is entered, can I just enter a certain number of scores and then have them all appear when I hit cancel in my Inputbox? And what's the easiest way to stick a 0 in the slot if a number in that scorerange isn't available?
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
|