BasicMath

#include <iostream>
#include <cstring>

using namespace std;

//Main
int main(int argc, char* argv[]) {

//Variables
double result;
double test;

//Check input from user
if ((argc != 4) || (strlen(argv[2]) != 1) || (sscanf_s(argv[1], “%d”, &test) != 1) || (sscanf_s(argv[3], “%d”, &test) != 1)) {

cout << “[number] [+-x/] [number] <ENTER>” << endl;
return 1;

}
else {

if (argv[2][0] == ‘+’) {
result = atof(argv[1]) + atof(argv[3]);
}
else if (argv[2][0] == ‘-‘) {
result = atof(argv[1]) – atof(argv[3]);
}
else if (argv[2][0] == ‘x’) {
result = atof(argv[1]) * atof(argv[3]);
}
else if (argv[2][0] == ‘/’) {

if (atof(argv[3]) == 0) {
cout << “Cannot divide by zero.” << endl;
return 2;
}
else {
result = atof(argv[1]) / atof(argv[3]);
}
}
else {
cout << “[number] [+-x/] [number] <ENTER>” << endl;
return 1;
}

cout << result << endl;

return 0;

}

}