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 !!!"); } } } }

22nd Jan 2019, 6:23 PM
Abdul Bari Abbasi
Abdul Bari Abbasi - avatar
5 Answers
+ 2
Replace the ||'s with &&'s.
22nd Jan 2019, 6:34 PM
Dennis
Dennis - avatar
+ 3
Use code playground to write your code and share the link
22nd Jan 2019, 6:31 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 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.
22nd Jan 2019, 6:46 PM
Dennis
Dennis - avatar
0
Hey dennis replacing || with && works.but, can you explain how this is working???
22nd Jan 2019, 6:39 PM
Abdul Bari Abbasi
Abdul Bari Abbasi - avatar
0
Thank you so much dennis :)
22nd Jan 2019, 7:04 PM
Abdul Bari Abbasi
Abdul Bari Abbasi - avatar