Home » questions » Is this Pseudocode correct?

Is this Pseudocode correct?

2006-08-02 19:52:21, Category: Programming & Design
‘Comment 90-100 = A 80-89 = B 70-79 = C 60 – 69 = D Under 60 = F INPUT: Student name, Raw Exam Score One, Raw Exam Score Two, Raw Exam Score Three OUTPUT: Student name "received a grade of” Letter grade (based on average of three scores) VARIABLES: NAME, S1, S2, S3, AS, GRADE Pseudocode Start Read NAME, S1, S2, S3 AS = (S1 + S2 + S3) / 3 IF AS => 90 AND AS =< 100 THEN GRADE = A ELSE IF AS => 80 AND AS =< 89 THEN GRADE = B ELSE IF AS => 70 AND AS =< 79 THEN GRADE = C ELSE IF AS => 60 AND AS =< 69 THEN GRADE = D ELSE IF AS < 60 THEN GRADE = F ENDIF ENDIF ENDIF ENDIF Write Write NAME, “received a grade of ", GRADE Stop Or will the division of three require an integer or double?

Answers

  1. SnowXNinja

    On 2006-08-02 20:38:01


    An integer for Variable AS will ensure that the grade is picked up, if your using F90 or (hopefully) something newer then a case statement is much more appropriate for this problem. If AS is an integer then, it will round to the nearest integer when assigned a single or double precision number., such as the group grade. Select Case AS Case IS < 60 Grade = F Case 61 to 69 Grade = D Case 70 to 79 Grade = C Case 80 to 89 Grade = B Case 90 to 100 Grade = A Case Else Print: Error, Grade is over 100 End Select
  2. sheeple_rancher

    On 2006-08-02 20:05:19


    Stick with integer. Reason: you can have fractional results which break your spec. 80-89 = B ... and 79.67 gets??? 70-79 = C Or you could do the double thing followed by a ROUND operation to get back to integers.