BHXSpecter

Exercise 1 Done

Nov 7th, 2011
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. const int SENTINEL = -999;
  4.  
  5. int main()
  6. {
  7.     double n = 0, sum = 0, temp = 1;
  8.  
  9.     cout << "Enter a number(Enter -999 to exit): ";
  10.     cin >> n;
  11.     cout << endl;
  12.  
  13.     while (n != SENTINEL)
  14.     {
  15.         if (n == 0)
  16.         {
  17.             sum = 1;
  18.             cout << sum << endl;
  19.         }
  20.         else
  21.         {
  22.             while (n != 0)
  23.             {
  24.                 temp = temp * n;
  25.                 n = n - 1;
  26.             }
  27.             cout << temp << endl;
  28.         }
  29.        
  30.         temp = 1;
  31.         cout << "Enter a number(Enter -999 to exit): ";
  32.         cin >> n;
  33.         cout << endl;
  34.     }
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment