0
where is the error in this code?
#include <stdio.h> int main (){ int english,islamiat,maths,urdu,science; float p=0; printf("Enter the obtained marks in each subject : "); printf("\nEnglish = "); scanf("%d",&english); printf("Islamiat = "); scanf("%d",&islamiat); printf("Maths = "); scanf("%d",&maths); printf("Urdu = "); scanf("%d",&urdu); printf("Science = "); scanf("%d",&science); p=(english+islamiat+maths+science+urdu)/5; if (p>=60 || p<=100){ printf("First Division."); } else { if(p>=50 || p<=59){ printf("Second Division."); } else { if(p>=40 || p<=49) { printf("Third Division"); } else { printf("Failed !!!"); } } } }
5 Answers
+ 2
Replace the ||'s with &&'s.
+ 3
Use code playground to write your code and share the link
+ 2
let p have the value 30 for example.
In the first if it evaluates like this:
Is p bigger or equal to 60? No
Is p smaller or equal to 100? Yes
Since it is a ||, only one of these has to be true.
You could pick any other value for p and 1 of these conditions will always be true.
If you used && instead, then both conditions have to be true, which can only happen if the value of p is between 60 and 100.
0
Hey dennis replacing || with && works.but, can you explain how this is working???
0
Thank you so much dennis :)