improve calculation accuracy
Allow using float point arguments to avoid truncation. Test: Add (4.9, 4.9) should return 10. Signed-off-by: Sergii Piatakov <sergii.piatakov@globallogic.com> formatting: use tabs instead of spaces Signed-off-by: Sergii Piatakov <sergii.piatakov@globallogic.com>
This commit is contained in:
parent
976f6913db
commit
e0a2d20626
|
@ -1,11 +1,11 @@
|
||||||
#include "calculator.h"
|
#include "calculator.h"
|
||||||
|
|
||||||
int Calculator::Add (int a, int b)
|
int Calculator::Add (double a, double b)
|
||||||
{
|
{
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Calculator::Sub (int a, int b)
|
int Calculator::Sub (double a, double b)
|
||||||
{
|
{
|
||||||
return Add (a, -b);
|
return Add (a, -b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
class Calculator
|
class Calculator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int Add (int, int);
|
int Add (double, double);
|
||||||
int Sub (int, int);
|
int Sub (double, double);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif//CALCULATOR_H
|
#endif//CALCULATOR_H
|
||||||
|
|
Loading…
Reference in New Issue