-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo3.hpp
37 lines (32 loc) · 890 Bytes
/
demo3.hpp
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
#include <iostream>
#include <limits>
namespace demo_gdb {
int product(int a, int b) {
static int count {0};
if (count == b)
return a; // <-- bug here
++count;
return a + product(a, b);
}
void demo3(int a, int b)
{
int sum, sub, div, prod;
sum = a + b;
sub = a - b;
if (b == 0)
div = std::numeric_limits<int>::max();
else
div = a / b;
prod = product(a, b);
long total {0};
total += sum;
total += sub;
total += div;
total += prod;
std::cout << "sum = " << sum << std::endl;
std::cout << "sub = " << sub << std::endl;
std::cout << "div = " << div << std::endl;
std::cout << "prod = " << prod << std::endl;
std::cout << "tot = " << total << std::endl;
}
}