Electrical and Computer Engineering
13 of 23
UAH
CPE 112
Nested Logic
•cin.get(inChar); // Initialize outer loop
•while (cin) // Outer loop test
•{
•   commaCount = 0; // Initialize inner loop
•  // (Priming read for outer
• // loop also primes this one
•   while (inChar != ‘\n’) // Inner loop test
•   {
•      if (inChar == ‘,’)
•         commaCount++;
•      cin.get(inChar);  // Update inner loop condition
•   }
•   cout << commaCount << endl;
•   cin.get(inChar); // Update outer loop condition
•}