#include #include // do // { // STATEMENTS // } // while (CONDITION); // // // // while (CONDITION) // { // STATEMENTS // } int main() { long int n; long int total; long int i; cout << "Enter an integer: "; cin >> n; //cout << "The fancy formula says " << n*(n+1)/2 << endl; // HERE ARE THREE WAYS OF DOING THE SAME THING total = 0; // Order of operations: // (1) initialization // (2) test loop execution condition // (3) stuff inside loop // (4) repeat expression is evaluated // (5) test loop execution condition // (6) stuff inside loop // ... // for (INITIALIZATION; LOOP EXECUTION CONDITION; REPEAT EXPRESSION) for (i = 1; i <= n; ++i) { total += i; } //total = 0; //i = 1; //while (i <= n) //{ // total += i; // ++i; //} //total = 0; //while (n > 0) //{ // total += n; // n--; // same thing as: n = n - 1; //} cout << "The total is " << total << endl; }