#include "stdafx.h"
#include <iostream>
#include <string>
#include "BrunoCalc.h"
double addition(double a, double b)
{
return (a + b);
}
double multiplication(double a, double b)
{
return (a * b);
}
double subtraction(double a, double b)
{
return (a - b);
}
double division(double a, double b)
{
return (a / b);
}
int main()
{
std::string expr;
while (expr != "`")
{
std::cout << "Calculate: ";
std::getline(std::cin, expr);
if (expr.find("+") != -1)
{
std::string part1;
std::string part2;
part1 = expr.substr(0, expr.find("+"));
part2 = expr.substr(expr.find("+") + 1, expr.length());
double a = atof(part1.c_str());
double b = atof(part2.c_str());
std::cout << "Result: " << addition(a, b) << std::endl;
}
else if (expr.find("-") != -1)
{
std::string part1;
std::string part2;
part1 = expr.substr(0, expr.find("-"));
part2 = expr.substr(expr.find("-") + 1, expr.length());
double a = atof(part1.c_str());
double b = atof(part2.c_str());
std::cout << "Result: " << subtraction(a, b) << std::endl;
}
else if (expr.find("*") != -1)
{
std::string part1;
std::string part2;
part1 = expr.substr(0, expr.find("*"));
part2 = expr.substr(expr.find("*") + 1, expr.length());
double a = atof(part1.c_str());
double b = atof(part2.c_str());
std::cout << "Result: " << multiplication(a, b) << std::endl;
}
else if (expr.find("/") != -1)
{
std::string part1;
std::string part2;
part1 = expr.substr(0, expr.find("/"));
part2 = expr.substr(expr.find("/") + 1, expr.length());
double a = atof(part1.c_str());
double b = atof(part2.c_str());
std::cout << "Result: " << division(a, b) << std::endl;
}
std::cout << std::endl;
}
return 0;
}