Why I am getting both outputs? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why I am getting both outputs?

#include<stdio.h> int main() { char a; printf("Enter the subject"); scanf("%s",&a); if(a= 'maths' ) { printf("You won ₹10"); } else if(a= 'science'); { printf("You won ₹20"); } else (a= 'science and maths'); { printf("You won ₹45"); } return 0; }

24th Jun 2021, 1:59 PM
Hamza
1 Answer
0
#include<stdio.h> #include<string.h> int main() { char a[50]; printf("Enter the subject"); scanf("%s",a); if(strcmp("maths",a)==0 ) { printf("You won ₹10"); } else if(strcmp("science",a)==0 ) { printf("You won ₹20"); } else { printf("You won ₹45"); } return 0; }
17th Jan 2022, 4:13 PM
Adi Nath Bhawani
Adi Nath Bhawani - avatar