Chapter 4 Control Structures: Part 1 107 (Web server type) Section
Chapter 4 Control Structures: Part 1 107 Section 4.9, we show how to develop a pseudocode algorithm. Counter-controlled repetition is also called definite repetition because the number of repetitions is known before the loop begins executing. 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 Fig. 4.6 Pseudocode algorithm that uses counter-controlled repetition to solve the class-average problem. 1 // Fig. 4.7: Average1.cs 2 // Class average with counter-controlled repetition. 3 4 using System; 5 6 class Average1 7 { 8 static void Main( string[] args ) 9 { 10 int total, // sum of grades 11 gradeCounter, // number of grades entered 12 gradeValue, // grade value 13 average; // average of all grades 14 15 // initialization phase 16 total = 0; // clear total 17 gradeCounter = 1; // prepare to loop 18 19 // processing phase 20 while ( gradeCounter <= 10 ) // loop 10 times 21 { 22 // prompt for input and read grade from user 23 Console.Write( "Enter integer grade: " ); 24 25 // read input and convert to integer 26 gradeValue = Int32.Parse( Console.ReadLine() ); 27 28 // add gradeValue to total 29 total = total + gradeValue; 30 Fig. 4.7 Class average program with counter-controlled repetition. (Part 1 of 2.)
Note: In case you are looking for affordable and reliable webhost to host and run your business application check Vision php5 hosting services