Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Back To School and Lost Pt.2

    Hey there,

    I received some aid from a member earlier and taking his advice, think I got it right with my assignment. I don't know if he is on to check my work but would like helpful feedback on it, if possible?

    The assignment was this:

    Write a program to read a list of exam scores (in the range 0 to 100) and to output the total number of grades and the number of grades in each letter=grade category.

    The end input is indicated by a negative score as a sentinel value. (The negative value is used only to end the loop, so do not use it in the calculations.

    Example:
    88
    93
    55
    77
    100
    -1

    (The output would be)
    Total number of grades = 5
    Number of A's =2
    Number of B's = 1
    Number of C's =1
    Number of D's = 0
    Number of F's =1
    Must prompt user to run again


    I've done this thus far:

    //Define Variables for review by fellow programmers:
    int countA = 0
    int countB = 0
    int countC = 0
    int countD = 0
    int countF = 0
    int InputScore

    //Input
    Write “Input the grades for Class #1.”
    InputScore

    While InputScore >= 0
    If (InputScore >= 90) Then
    countA++

    If (InputScore < 90&&InputScore>=80) Then
    countB++

    If (InputScore < 80&&InputScore>=70) Then
    countC++

    If (InputScore < 70&&InputScore>=60) Then
    countD++

    If (InputScore < 60&&InputScore>=0) Then
    countF++
    EndWhile

    //Concatenates

    totalGrade = countA+countB+countC+CountD+countF
    Write "Total Grades are" + totalGrade
    Write "A" + countA
    Write "B" + countB
    Write "C" + countC
    Write "D" + countD
    Write "F" + countF


    If it needs any improvement or I'm missing anything, please do point it out, as I need to complete this by tomorrow afternoon! D8

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Not quite.

    You only input *ONE* grade, before the loop.

    You need to get one grade EACH TIME through the loop.

    And though your IF tests work, you can make it simpler if you use ELSE, as well.

    Oh, w.t.h.
    Code:
    While True
       Write “Input one grade"
       Read InputScore
       If InputScore < 0 Then breakOutOfLoop /* how you break out depends on language*/
    
       If (InputScore >= 90) Then
           countA++
       Else If InputScore >=80) Then
           countB++
       Else If InputScore>=70 Then
           countC++
       Else If InputScore>=60 Then
           countD++
       Else
            countF++
       End If
    EndWhile
    Now, this pseudo-code won't compile in any language I know. It's kind of a hodge-podge between VBScript and JavaScript. But the logic works.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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