Lec 17-Example

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

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

View Full Document Right Arrow Icon
Asma Ahmad
Background image of page 1

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

View Full DocumentRight Arrow Icon
To review what we have studied so far
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
#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; }
Background image of page 5

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

View Full DocumentRight Arrow Icon
Enter grade: 98 Enter grade: 76 Enter grade: 71 Enter grade: 87 Enter grade: 83 Enter grade: 90 Enter grade: 57 Enter grade: 79 Enter grade: 82 Enter grade: 94 Class average is 81
Background image of page 6
void main (void) {        int number1 = 10;        while (
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

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

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online