/* loop3.cpp Dave Klick CIS 150 2017-02-14 Demonstration of accumulator. */ #include using namespace std; int main() { int start, stop, total, temp; cout << "Enter starting number: "; cin >> start; cout << "Enter ending number: "; cin >> stop; // swap numbers if stop is less than start if (start > stop) { temp = start; start = stop; stop = temp; } // add up all the numebrs in the range // no init needed since start (the loop counter) is already set // important to initialize accumulator (total) to 0 total = 0; for (; start <= stop; start++) { total = total + start; } cout << "The total is " << total << endl; return 0; }