0
How can i use a char variable for an operation eg. if i store a + in variable plus, how can i use it in anarithmetic operation
This is related to C++
5 Réponses
+ 1
Ohk thanks hey ☺
0
in a switch
....
int a=5, b=3;
char op;
printf("Enter an operator");
scanf("%c", &op);
switch (op)
{
case '+': printf("%d",a+b);break;
case '-': printf("%d",a-b); break;
/* All the others */
default: printf("Not an operator.\n");
}
....
0
But what about in c++
0
I'm a beginner so in a bit confused with this
0
just replace the scanf with cin and printf with cout Im not sure about the cpp syntax. if anything, spend some more time in the tutorial.