Pls anyone help me to find mistake in my code its only printing if condition 1 nothing else | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Pls anyone help me to find mistake in my code its only printing if condition 1 nothing else

#include <stdio.h> int main() { int passed; printf("how many subjects have you passed"); scanf("%d",&passed); if(passed=2){ printf("you have passed in maths and science\n"); printf("your price is 45 ruppes\n"); } else if(passed=1){ printf("you have passed in 1 subject"); printf("your price is 15 ruppes"); } return 0; } https://code.sololearn.com/c9418mx4ZyGR/?ref=app

24th Jul 2021, 7:55 AM
Shayan Bhattacharjee
3 Answers
+ 1
Shayan Bhattacharjee Because you are not comparing value in if case. You have used single equal (=) which is used to assign value. Double equal (==) is used for comparison.
24th Jul 2021, 8:03 AM
A͢J
A͢J - avatar
0
Shayan Bhattacharjee Why did you share another person code. Is it necessary?
24th Jul 2021, 8:03 AM
A͢J
A͢J - avatar
0
I didn't knew how to share post sorry for disturbing
24th Jul 2021, 8:31 AM
Shayan Bhattacharjee