{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lec 17-Example

# Lec 17-Example - Asma Ahmad To review what we have studied...

This preview shows pages 1–8. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
To review what we have studied so far
Example A class of ten students took a quiz. The grades (integers in the range 0 to 100) for this quiz are available to you. Determine the class average on the quiz. Counter-controlled repetition Loop repeated until counter reaches certain value Same as we have studied in “Program Counter” register of control unit.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Pseudocode for example: Set total to zero Set grade counter to one While grade counter is less than or equal to ten Input the next grade Add the grade into the total Add one to the grade counter Set the class average to the total divided by ten Print the class average Next: C code for this example
#include <iostream.h> void main (void) {      int total = 0, gradeCounter = 0, inputGrade = 0; float average = 0;       while ( gradeCounter <= 10 ) { cout<<“Enter the grade”; cin>>inputGrade; total = total + inputGrade; gradeCounter = gradeCounter + 1; } average = total/10; cout<<“The average is :”<<average; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document