Hello everyone.
I am learning C and am stucked somewhere in the code. Basically I want to assign the marks to the grade. However my output comes out to be totally different from what I want. Here is my code:
Code:
# include<stdio.h>
int main ()
{
int total = 0, marks = 0, count = 1;
float avg = 0;
printf( "Enter the marks obtained or -1 to quit:\n");
scanf( "%d", &marks );
while ( marks != -1 )
{
total = total + marks;
count ++;
printf( "Enter the marks obtained or -1 to quit:\n");
scanf( "%d", &marks );
}
if( count != 0 )
{
avg = (float) total/count;
printf( "Marks in grades are: %.2f ", avg);
}
else if ( avg >= 80.00 )
printf( "Marks is in grades 'A'.\n");
else if( avg < 80.00 && avg >= 70.00 )
printf( "Marks is in grades 'B'. \n");
else if( avg < 70.00 && avg >= 60.00 )
printf( "Marks is in grades 'C'. \n");
else if( avg < 60.00 && avg >= 40.00 )
printf( "Marks is in grades 'D'.\n");
else
printf( "\nMarks is in grades 'F'. \n");
printf( "You enter: %d times\n", count);
return 0;
}
Any comments
Bookmarks