It's a code that calculates the total and average points by entering the scores for each subject, but I don't know how to write the average point up to one decimal place.What should I do?
#include<stdio.h>
int main(void){
double a, b, c, Sum, Ave;
printf("Input your scores:\n";
printf("Math:");
scanf("%lf", & a);
printf("English:");
scanf("%lf", &b);
printf("Science:");
scanf("%lf", &c);
Sum = a + b + c;
Ave = Sum/3;
if(Sum<=179)
printf("Your grade is F, Average is%.lf.\n", Ave);
if(Sum>=180&Sum<=209)
printf("Your grade is C, Average is %.lf.\n", Ave);
if(Sum>=210&Sum<=239)
printf("Your grade is B, Average is %.lf.\n", Ave);
if(Sum>=240&Sum<=269)
printf("Your grade is A, Average is %.lf.\n", Ave);
if(Sum>=270)
printf("Your grade is A++, Average is%.lf.\n", Ave);
return 0;
}
%lf
instead of %lf
will match the display up to 1 decimal place.
printf("Your grade is F, Average is %.1lf.\n", Ave);
© 2024 OneMinuteCode. All rights reserved.