Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int SENTINEL = -999;
- int main()
- {
- double n = 0, sum = 0, temp = 1;
- cout << "Enter a number(Enter -999 to exit): ";
- cin >> n;
- cout << endl;
- while (n != SENTINEL)
- {
- if(n < 0)
- {
- cout << "Only positive numbers!" << endl;
- }
- else if(!cin.good())
- {
- cout << "No letters!" << endl;
- cin.clear();
- cin.ignore(100, '\n');
- }
- else if (n == 0)
- {
- sum = 1;
- cout << sum << endl;
- }
- else
- {
- while (n != 0)
- {
- temp = temp * n;
- n = n - 1;
- }
- cout << temp << endl;
- }
- temp = 1;
- cout << "Enter a number(Enter -999 to exit): ";
- cin >> n;
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment