Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Please identify the error

0 votes
asked Oct 1, 2018 by Rishabh Sinha
#include <stdio.h>

void main()
{
    int a,b,c,e,f,sum=0;
    float avg;
printf("enter number of 5 subjects");
scanf ("%d%d%d%d%d,&a,&b,&c,&e,&f");
sum=sum+a+b+c+e+f;
avg=sum/5;
if (avg>75) printf ("Distinction");
if (75<avg<60) printf("1st Division");
if (60<avg<50) printf("2nd divison");
if (50<avg<40) printf("3rd Divison");
if (avg<40) printf("fail");   
}

2 Answers

0 votes
answered Oct 1, 2018 by anonymous

Check the highlighted areas to find out errors in your code:

#include <stdio.h>

int main()
{

int a,b,c,e,f,sum=0;
float avg;
printf("enter number of 5 subjects");
scanf ("%d%d%d%d%d",&a,&b,&c,&e,&f);
sum=sum+a+b+c+e+f;
avg=sum/5;
if (avg>75) printf ("Distinction");
else if (75<avg<60) printf("1st Division");
else if (60<avg<50) printf("2nd divison");
else if (50<avg<40) printf("3rd Divison");
else if (avg<40) printf("fail"); 
}

0 votes
answered Oct 2, 2018 by 박병규 (140 points)

I think there should be 'greater than or equal' because your statements cannot catch avg values such as 75, 60, 50, and 40.

Also, you should distinct 'greater than' condition and 'less than' condition. For example, use '60 <= avg && avg < 75', not '60<avg<75' (You even switched the orders in your question!).

Finally, if you want to print only one sentence different by average's range, you should use 'else if' to distinguish score ranges.

So the revised version should be...

#include <stdio.h>

void main()
{
    int a,b,c,e,f,sum=0;
    float avg;
printf("enter number of 5 subjects");
scanf ("%d%d%d%d%d,&a,&b,&c,&e,&f");
sum=sum+a+b+c+e+f;
avg=sum/5;
if (avg >= 75) printf ("Distinction");
else if (60 <= avg && avg < 75) printf("1st Division");
else if (50 <= avg && avg < 60) printf("2nd divison");
else if (40 <= avg && avg < 50) printf("3rd Divison");
else printf("fail");
 // You can leave out the 'else if' statement because the last condition (avg < 40) is the only left else condition. (Sorry my english is bad :D)
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...