Can you guys tell me the error? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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 "); } }

3rd Jun 2021, 10:43 AM
PARV SHARMA
PARV SHARMA - avatar
4 Antworten
+ 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
3rd Jun 2021, 10:55 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
Bro don't use `d` as switch argument as `d` has not any int value , you haven't taken input for `d`
3rd Jun 2021, 10:52 AM
saurabh
saurabh - avatar
+ 1
PARV SHARMA you get input for a and b, but you do not initialize (nor get input for) d ;)
3rd Jun 2021, 10:53 AM
visph
visph - avatar
3rd Jun 2021, 11:23 AM
PARV SHARMA
PARV SHARMA - avatar