0

Anyone to help me with the code below.

Its telling me that i am comparing a pointer and an integer which is an error. /*calculator*/ #include <stdio.h> int main(){ char add=1; char mult=2; char div=3; char sub=4; char sign[1]; printf("Enter the sign for your calculation:\t"); scanf("%s",sign); if(sign==add){ int a,b,sum; printf("\nEnter the first number"); scanf("%d",&a); printf("\nEnter the second number:"); scanf("%d",&b); sum=a+b; printf("\nThe sum of the two values is:%d",sum); } else if(sign==sub){ int a,b,difference; printf("\nEnter the first number:"); scanf("%d",&a); printf("\nEnter the second number:"); scanf("%d",&b); difference=a-b; printf("\nThe answer is:%d",difference); } else if(sign==mult){ int a,b,product; printf("\nEnter the first number:"); scanf("%d",&a); printf("\nEnter the second number:"); scanf("%d",&b); product=a*b; printf("\nThe product is:%d",product); } else if(sign==div){ int a,b; float c; printf("\nEnter the first number:"); scanf("%d",&a); printf("\nEnter the second number:"); sca

2nd Feb 2020, 1:05 PM
Wadika
Wadika - avatar
2 Antworten
+ 1
These changes needed... char add='1'; //or take it as + , If it is number like just 1, then it is stored as converted to ascii value 48. No case matches char mult='2; char div='3'; char sub='4'; char sign; //just use char printf("Enter the sign for your calculation:\t"); scanf("%c",&sign);
2nd Feb 2020, 2:22 PM
Jayakrishna 🇮🇳