Grade Average Code#include <stdio.h>
#include <stdlib.h> int main() { int score1; int score2; int score3; int score4; int score5; printf("Enter score 1: "); scanf("%d",&score1); printf("Enter score 2: "); scanf("%d",&score2); printf("Enter score 3: "); scanf("%d",&score3); printf("Enter score 4: "); scanf("%d",&score4); printf("Enter score 5: "); scanf("%d",&score5); int grade = (score1+score2+score3+score4+score5)/5; if(grade>=90 && grade<=100){ printf("Your grade is A\n"); } else if(grade>=80 && grade<=89){ printf("Your grade is B\n"); } else if(grade>=70 && grade<=79){ printf("Your grade is C\n"); } else if(grade>=60 && grade<=69){ printf("Your grade is D\n"); } else{ printf("Your grade is F\n"); } return 0; } |
Grade Average DetailsThis code will take five numbers/scores and average them to find a grade. Each score have their own variable. After each score is entered an equation adds all the scores together and then divides by 5. After that the if statements determine which grade is printed out based on the averaged score. If a score is below 60 then the else statement prints a F.
Real Time ApplicationsThis can be used for part of a structure for a real grading program. The code can also be changed to score different things like sports scores for example.
|