// Author: Keith Shomper // Date: 9/26/03 // Purpose: To demonstrate the while loop by computing a factorial // ** WARNING ** This program as originally written has an error ** WARNING ** #include using namespace std; int main() { int N, originalN, factorial; // prompt the user for the value of N cout << "What number would you like to compute the factorial for? "; cin >> N; // Save the value of N for the output originalN = N; // initialization of the loop can occur many ways, i.e., we can use the // number N as our loop control variable and stop when it hits zero I // computer the factorial while (N > 0) { // T // combine the current number with the product we are building E factorial *= N; // update N so we repeatedly use smaller and smaller values of N M --N; } // Display the result cout << originalN << "! is " << factorial << endl; return 0; }