...

View Full Version : Back To School and Lost Pt.2

CMST385
10-10-2011, 05:40 PM
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

Old Pedant
10-10-2011, 07:55 PM
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.

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.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum