Electrical and Computer Engineering
5 of 23
UAH
CPE 112
Another Summing Example
•count = 0; // Initialize event counter
•sum = 0; // Initialize sum
•lessThanTen = true; // Initialize flag
•
•while (lessThanTen)
•{
•   cin >> number; // Get the next value
•   if (number % 2 == 1) // Is the value odd?
•   {
•      count++; // Yes – Increment counter
•      sum = sum + number; // Add value to sum
•      lessThanTen = (count < 10);  // Update flag
•   }
•}
•