Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions homework/calculate/calculate.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
#pragma once
#include <string>

auto add(const int lhs, const int rhs) -> std::string {
return std::to_string(lhs + rhs);
}

auto subtract(const int lhs, const int rhs) -> std::string {
return std::to_string(lhs - rhs);
}

auto multiply(const int lhs, const int rhs) -> std::string {
return std::to_string(lhs * rhs);
}

auto divide(const int lhs, const int rhs) -> std::string {
if (rhs != 0) {
return std::to_string(lhs / rhs);
}
return "Division by 0";
}

std::string calculate(const std::string& command, int first, int second) {
// TODO: Implement your solution here and return proper value
return "";
if (command == "add") {
return add(first, second);
} else if (command == "subtract") {
return subtract(first, second);
} else if (command == "multiply") {
return multiply(first, second);
} else if (command == "divide") {
return divide(first, second);
}
return "Invalid data";
}