Nov 29 2012, 12:23 PM
M. Bison, post: 81035, member: 359 Wrote:98+99+88+87+79 = 451 which divided by 500 is less than 1. The datatype is an int which means anything beyond the integer is dropped, making it 0. The result is 0 * 100 = 0.THANKS about it MAN!!! THANKS AGAIN!!
Try this:
Code:#include<stdio.h>
int main()
{
int m1,m2,m3,m4,m5,per;
printf("Enter the marks of five subjects\n");
scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);
per=(int)(((float)(m1+m2+m3+m4+m5))/500.0*100.0);
if(per>=80)
printf("First Division\n");
else if(per>=60)
printf("Second Division\n");
else if(per>=50)
printf("Third Division\n");
else
printf("Fail");
return 0;
}
PS: If you intend on rounding to the nearest integer, add 0.5 before the cast to int.
Double post
M. Bison, post: 81035, member: 359 Wrote:PS: If you intend on rounding to the nearest integer, add 0.5 before the cast to int.Please can u explain this further?