Is there any way to make an operation into a variable, in order to get it as an input value? Here is a short example of a general idea, I know this will no where near work, its just an extremely simplified thing for context of the idea:
#include <iostream>
#include <math.h>
#include <string>
usingnamespace std;
int main ()
{
int number1, number2;
cin >> number1;
cin >> number2;
char operation;
if (operation == "+")
{
cout << number1 + <<
}
if (operation == "-")
{
cout << number - <<
}
else
{
cout << "
cout << number 2 << endl;
}
return 0;
Is it even possible to get an operation as an character or even a floating value, and if so, how would it work? And if this code may work, with adjustment that would be much simpler! Thanks!
So in my attempt to make a basic calculator, with your method of turning the character into an operation I came up with this code, however I have had two main problems, this is the over all code:
My second problem is that, when a number or anything is entered for char operation besides the given operation values, it will automatically do multiplication. I tried to stop this, but it still does not work at all:
1 2 3 4 5 6 7 8
elseif (0 <= operation or operation > 0)
{
cout << "That is not recognized as an operation, /n try (+, -, /, *, x)" << endl;
newLine ();
{
return main ();
}