-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorial.cpp
More file actions
executable file
·52 lines (46 loc) · 892 Bytes
/
Copy pathFactorial.cpp
File metadata and controls
executable file
·52 lines (46 loc) · 892 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Calculator.h"
Factorial::Factorial(){
//donothing
}
Factorial::~Factorial() {
//do nothing
}
string Factorial::simplify(string n, string degree, string op) {
return "";
}
bool Factorial::check(string value1, string value2) {
return true;
}
string Factorial::calculate(string num1, string num2, string action)
{
for (int i = 0; i < num1.length(); i++)
{
if (num1[i] == '-')
{
return "can’t contain negative numbers";
break;
}
if (num1[i] == '/')
{
return "can’t contain fractions";
break;
}
}
stringstream str;
str << num1;
int factorial;
str >> factorial;
int total = factorialHelper(factorial);
string Result;
ostringstream convert;
convert << total;
Result = convert.str();
return Result;
}
int Factorial::factorialHelper(int factorial)
{
if (factorial <= 0)
return 1;
else
return factorial * factorialHelper(factorial - 1);
}