/* testrep5.cpp CIS 150 6/7/2005 David Klick Demonstration of accumulator (for product). */ #include using std::cout; using std::cin; int main(void) { int ctr; // loop counter int fact; // accumulator for factorial int num; // number user enters // ask user for number to get factorial of cout << "Enter an integer (1 through 10): "; cin >> num; if (num<1 || num>10) { cout << "Error: Input out of range\n"; } else { // calculate factorial fact = 1; for (ctr=2; ctr<=num; ctr++) { fact *= ctr; } cout << "The factorial of " << num << " is " << fact << '\n'; } return 0; } /* Sample output: Enter an integer (1 through 10): 7 The factorial of 7 is 5040 */