From e0a2d2062695f411f710673710fda6ec2e852df5 Mon Sep 17 00:00:00 2001 From: Sergii Piatakov Date: Thu, 15 Nov 2018 15:21:34 +0200 Subject: [PATCH] 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 formatting: use tabs instead of spaces Signed-off-by: Sergii Piatakov --- calculator.cpp | 8 ++++---- calculator.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/calculator.cpp b/calculator.cpp index 3c63184..f323e14 100644 --- a/calculator.cpp +++ b/calculator.cpp @@ -1,11 +1,11 @@ #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); } diff --git a/calculator.h b/calculator.h index 84ff414..d59d596 100644 --- a/calculator.h +++ b/calculator.h @@ -3,9 +3,9 @@ class Calculator { - public: - int Add (int, int); - int Sub (int, int); + public: + int Add (double, double); + int Sub (double, double); }; #endif//CALCULATOR_H