forked from jieniyimiao/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex6_04.cpp
36 lines (27 loc) · 977 Bytes
/
ex6_04.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
=================================================================================
C++ Primer 5th Exercise Answer Source Code
Copyright (C) 2014-2015 github.com/pezy/CppPrimer
Write a function that interacts with the user, asking for a
number and generating the factorial of that number. Call this function from
main.
If you have questions, try to connect with me: pezy<[email protected]>
=================================================================================
*/
#include <iostream>
void factorial_with_interacts() {
int num;
std::cout << "Please input a positive number: ";
while ( std::cin >> num && num < 0 )
std::cout << "Please input a positive number again: ";
std::cout << num;
unsigned long long result = 1;
while (num > 1) result *= num--;
std::cout << "! is ";
if ( result ) std::cout << result << std::endl;
else std::cout << "too big" << std::endl;
}
int main()
{
factorial_with_interacts();
}