Skip to content

Commit

Permalink
Implementation of a function solving mathematical operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Macias89-SC committed Sep 5, 2024
1 parent 6dba22f commit d3c6892
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions homework/calculate/calculate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@
#include <string>

std::string calculate(const std::string& command, int first, int second) {
// TODO: Implement your solution here and return proper value
return "";
if (command == "add") {
int AddNumber = first + second;
std::string str = std::to_string(AddNumber);
return str;
}
else if (command == "subtract"){
int SubNumber = first - second;
std:: string str = std::to_string(SubNumber);
return str;
}
else if (command == "multiply"){
int MultiNumber = first * second;
std::string str = std::to_string(MultiNumber);
return str;
}
else if ( command == "divide"){
if (second !=0){
int DivNumber = first / second;
std::string str = std::to_string(DivNumber);
return str;
}
else
{
return "Division by 0";
}

}
else
return "Invalid data";
}

0 comments on commit d3c6892

Please sign in to comment.