Results 1 to 9 of 9

Thread: test scores help

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    8

    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?

  2. #2
    "The" RedHeadedLefty
    Join Date
    Aug 2005
    Location
    College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
    Posts
    4,495

    Re: test scores help

    You can use either...
    VB Code:
    1. If MyScore > somenumber or MyScore < somenumner then ...
    2.      'some code
    3. End If
    VB Code:
    1. Select Case MyScore
    2.     Case SomNumber to SomeOtherNumber
    3.           'some code
    4. End Select

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    8

    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


  4. #4
    Addicted Member Crushinator's Avatar
    Join Date
    Jan 2006
    Location
    The Dark Side of the Moon, MD
    Posts
    179

    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.

  5. #5
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: test scores help

    Quote Originally Posted by gigemboy
    You can use either...
    VB Code:
    1. If MyScore > somenumber or MyScore < somenumner then ...
    2.      'some code
    3. End If
    VB Code:
    1. Select Case MyScore
    2.     Case SomNumber to SomeOtherNumber
    3.           'some code
    4. 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
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    8

    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:
    1. Dim scorestr As String
    2.         Dim score As Integer
    3.         Dim count As Integer
    4.         Dim total As Integer
    5.         Dim average As Single        
    6.         Dim Acount As Integer
    7.         Dim Bcount As Integer
    8.         Dim Ccount As Integer
    9.         Dim Dcount As Integer
    10.         Dim Fcount As Integer
    11.  
    12. Do Until scorestr = ""
    13.             If IsNumeric(scorestr) Then
    14.                 score = Val(scorestr)
    15.                 If score >= 0 AndAlso score <= 100 Then
    16.                     total += score
    17.                     count += 1
    18.                     Acount += 1
    19.                     Bcount += 1
    20.                     Ccount += 1
    21.                     Dcount += 1
    22.                     Fcount += 1
    23.  
    24.           Select Case score
    25.                 Case 90 To 100
    26.                     Me.lblAs2.Text = Acount
    27.                 Case 80 To 89
    28.                     Me.lblBs2.Text = Bcount
    29.                 Case 70 To 79
    30.                     Me.lblCs2.Text = Ccount
    31.                 Case 60 To 69
    32.                     Me.lblDs2.Text = Dcount
    33.                 Case 0 To 59
    34.                     Me.lblFs2.Text = Fcount
    35.             End Select
    36.  
    37.  
    38.             Me.lblCount2.Text = Format(count)
    39.             Me.lblTotal2.Text = Format(total)
    40.             Me.lblAverage2.Text = Format(average, "N2")

  7. #7
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: test scores help

    VB Code:
    1. f IsNumeric(scorestr) Then
    2.                 score = Val(scorestr)
    3.                 If score >= 0 AndAlso score <= 100 Then
    4.                     total += score
    5.                     count += 1
    6.                     Acount += 1
    7.                     Bcount += 1
    8.                     Ccount += 1
    9.                     Dcount += 1
    10.                     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:
    1. Select Case score
    2.                 Case 90 To 100
    3.                     ACount +=1
    4.                     Me.lblAs2.Text = Acount
    5.                 Case 80 To 89
    6.                     BCount+=1
    7.                     Me.lblBs2.Text = Bcount
    8.                 Case 70 To 79
    9.                     Ccount+=1
    10.                     Me.lblCs2.Text = Ccount
    11.                 Case 60 To 69
    12.                     Dcount +=1
    13.                     Me.lblDs2.Text = Dcount
    14.                 Case 0 To 59
    15.                     FCount +=1
    16.                     Me.lblFs2.Text = Fcount
    17.             End Select

    You see, there's no reason to increment ALL the count variables every time it loops.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  8. #8
    "The" RedHeadedLefty
    Join Date
    Aug 2005
    Location
    College Station, TX Preferred Nickname: Gig Current Mood: Just Peachy Turnons: String Manipulation
    Posts
    4,495

    Re: test scores help

    Quote 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

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    8

    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
  •  



Click Here to Expand Forum to Full Width