What mistake is done in this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What mistake is done in this code?

#include <stdio.h> int main() { int a,b,c; scanf("%i",&a); scanf("%i",&b); printf("your answer="); scanf("%d",&c); if("c==+") printf("%d",a+b); else if("c==-") printf("%d",a-b); else if("c==*") printf("%d",a*b); else if("c==/") printf("%d",a/b); return 0; }

18th Jun 2022, 3:37 AM
Suraj kumar
Suraj kumar - avatar
3 Answers
+ 4
SoloProg also making char as c
18th Jun 2022, 2:12 PM
Mihir Lalwani
Mihir Lalwani - avatar
+ 3
Your condition are not correct in if statement you have to give condition you have written strings in double quotes remove them and take third input as a char type
18th Jun 2022, 5:19 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 3
#include <stdio.h> int main() { int a,b; char c; scanf("%i",&a); scanf("%i",&b); printf("your answer="); scanf("%c",&c); if("c=='+'") printf("%d",a+b); else if("c=='-'") printf("%d",a-b); else if("c=='*'") printf("%d",a*b); else if("c=='/'") printf("%d",a/b); return 0; } /* make c as char and make operator in ''*/
18th Jun 2022, 8:49 AM
Mihir Lalwani
Mihir Lalwani - avatar