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 | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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++

19th Apr 2021, 6:16 PM
Caroline Natasha Murenga
5 Réponses
+ 1
Ohk thanks hey ☺
19th Apr 2021, 6:57 PM
Caroline Natasha Murenga
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"); } ....
19th Apr 2021, 6:24 PM
Slick
Slick - avatar
0
But what about in c++
19th Apr 2021, 6:52 PM
Caroline Natasha Murenga
0
I'm a beginner so in a bit confused with this
19th Apr 2021, 6:52 PM
Caroline Natasha Murenga
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.
19th Apr 2021, 6:54 PM
Slick
Slick - avatar