108 Control Structures: Part 1 Chapter 4 31 (Free php web host)

108 Control Structures: Part 1 Chapter 4 31 // add 1 to gradeCounter 32 gradeCounter = gradeCounter + 1; 33 } 34 35 // termination phase 36 average = total / 10; // integer division 37 38 // display average of exam grades 39 Console.WriteLine( “nClass average is {0}”, average ); 40 41 } // end Main 42 43 } // end class Average1 Enter integer grade: 100 Enter integer grade: 88 Enter integer grade: 93 Enter integer grade: 55 Enter integer grade: 68 Enter integer grade: 77 Enter integer grade: 83 Enter integer grade: 95 Enter integer grade: 73 Enter integer grade: 62 Class average is 79 Fig. 4.7 Class average program with counter-controlled repetition. (Part 2 of 2.) Note the references in the algorithm (Fig. 4.6) to a total and a counter. The pseudocode variable total accumulates the sum of a series of values. A counter is a variable that counts in this case, that counts the number of grades entered. Variables that store totals normally should be initialized to zero before being used in a program; otherwise, the sum would include the previous value stored in the total s memory location. Testing and Debugging Tip 4.3 Initialize counters and totals. Line 6 begins the definition of class Average1. Remember that an application class definition must contain a Main method (lines 8 41) to begin execution of the application. Lines 10 13 declare variables total, gradeCounter, gradeValue and average to be of type int. Variable gradeValue will store the value the user inputs after the value is converted from a string to an int. Good Programming Practice 4.4 Always place a blank line between a declaration and executable statements. This makes the declarations stand out in a program and contributes to program clarity. Lines 16 17 are assignment statements that initialize total to 0 and grade- Counter to 1. Variables total and gradeCounter are initialized before they are
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision servlet hosting services

Leave a Reply