Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-10-2011, 05:40 PM   PM User | #1
CMST385
New to the CF scene

 
Join Date: Oct 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
CMST385 is an unknown quantity at this point
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
CMST385 is offline   Reply With Quote
Old 10-10-2011, 07:55 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:49 PM.


Advertisement
Log in to turn off these ads.