// Oldham, Jeffrey D. // 1999 Sep 07 // CS 1320 // // Program to Add Many Integers // input <- Prompted by the program, the user types zero or more integers. // output-> The integers' sum is printed. // We modified the previous program to add any number of integers. // To add many integers, we must repeatedly ask for integers. To do // something repeatedly, we use a while loop. First, we have to // identify the lines that should be repeatedly executed. #include int main() { // This group looks a lot like ... // int first_integer; // cout << "Please enter an integer: "; // cin >> first_integer; // this group ... // int second_integer; // cout << "Please enter an integer: "; // cin >> second_integer; // so we put them inside the while loop. while (/* add test of when to stop */) { int second_integer; cout << "Please enter an integer: "; cin >> second_integer; } int sum = first_integer + second_integer; cout << "The sum is " << sum << ".\n"; return 0; }