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
20 changes: 17 additions & 3 deletions homework/calculate/calculate.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
#pragma once
#include <stdexcept>
#include <string>

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