Ok, I've been working on this for about 4 hours, but I cannot get it to work! I'm starting with a char, then I need it to become a const char so I can use strcmp in my if statements. If there's anything wrong in that idea, please tell me what I have to do. If there's nothing wrong there, here's my code:
//Simple calculator.
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int calculate(int,const char,int);
int main()
{
using namespace std;
int a,b;
char operation[1];
cout << "Operations: +, -, *, /" << endl;
cout << "Number 1: ";
cin >> a;
cout << "Operation: ";
cin >> operation[1];
const char op[1] = "";
strcpy(op[1],operation[1]);
cout << "Number 2: ";
cin >> b;
cout << endl;
cout << "The answer is " << calculate(a,op[1],b);
cout << "Press any key to close this program.";
system("pause > nul");
return 0;
}
int calculate(int a, const char operation, int b)
{
using namespace std;
if(operation == "+")
{
return a + b;
}
if(operation == "-")
{
return a - b;
}
if(operation == "*")
{
return a * b;
}
if(operation == "/")
{
return a / b;
}
}
Just so you know, I'm a newbie at C++, so I don't understand anything about maps. Please help!