0
Can you guys tell me the error?
#include<stdio.h> void main() { int a,b,c,d; printf("Enter the values\n choose 1 for add \n choose 2 for minus \n choose 3 for multiple \n choose for division "); scanf("%d,%d",&a,&b); switch(d) { case 1: c = a + b ; printf("ans= %d \n",&c); break; case 2: c = a - b; printf("ans =%d \n",&c); break; case 3:c = a * b; printf("ans = %d \n",&c); break; case 4: c = a/b; printf("ans = %d \n",&c); break; default : printf("You choice is Invalid "); } }
4 Answers
+ 1
There are some mistakes in your code.
1.You have given "," in the scanf operator but it should be gap like this:
scanf("%d %d",&a,&b);
2.In the printf you forgot to write choose "4" for division.
3.You forgot to take the input for taking input of the work of your code.
4.You are not printing the address of the variables, you are printing the value so there's no need to give "&" in printf()
Optional:
You have given void main but int main is better than that.
After editing your code it should like this:
https://code.sololearn.com/ca23A0A15a16
+ 1
Bro don't use `d` as switch argument as `d` has not any int value , you haven't taken input for `d`
+ 1
PARV SHARMA
you get input for a and b, but you do not initialize (nor get input for) d ;)
+ 1