I want to create a program that reads a string containing two numbers and a operator and prints out the results. It is continuously showing error on arithmetic operators. For instance, how would I add two strings together?
int main()
{
string number1;
string number2;
string operation;
string answer;
cout << "Enter numbers with respective operations";
cout << "number 1";
cin >> number1;
cout << "number2";
cin >> number2;
cout << "operation";
cin >> operation;
if (operation == "+")
{
answer = number1 + number2;
cout << "the sum is " << answer << endl;
}
else if (operation == "-")
{
answer = number1 - number2;
cout << "the difference is " << answer << endl;
}
else if (operation == "*")
{
answer = number1 * number2;
cout << "the product is " << answer << endl;
}
else if (operation == "/")
{
answer = number1 / number2;
cout << "the answer is " << answer << endl;
}
else
{
cout << "invalid input" << endl;
}
getchar();
return 0;
}