I was given a task to create a program that:
1. convert to grade
2. calculate number of every grade like if there's inputted 5 times a score that equal to A then A = 5
3. calculate average of score (using function)
4. print stars depending of every grade A = 5 =*****, b = 2 = **
I couldn't figure out the number 2, i think there's a small problem with my code
Code:
#include <stdio.h>
#include "func.h"
int main()
{
int score, avg, count, total, student, aCount, bCount, cCount, dCount, eCount, k, skor, sick, haz;
total = 0;
student = 1;
aCount = 0;
bCount = 0;
cCount = 0;
dCount = 0;
eCount = 0;
char grade;
while (student <=10){
printf("Please enter the score: ");
scanf("%d", &score);
sick = score;
haz = counting(sick, aCount, bCount, cCount, dCount, eCount);
student++;
total = total + score;
grade = score2grade(score);
printf("Score = %d => grade=%c\n", score, grade);
}
avg = average(avg, total);
printf("The Average is %d\n", avg);
printf("A: %d = ", aCount);
for(k=1; k<=aCount;k++){
printf("%s", "*");}
printf("\n");
printf("B: %d = ", bCount);
for(k=1; k<=bCount;k++){
printf("%s", "*");}
printf("\n");
printf("C: %d = ", cCount);
for(k=1; k<=cCount;k++){
printf("%s", "*");}
printf("\n");
printf("D: %d = ", dCount);
for(k=1; k<=dCount;k++){
printf("%s", "*");}
printf("\n");
printf("E: %d = ", eCount);
for(k=1; k<=eCount;k++){
printf("%s", "*");}
printf("\n");
return 0;
}
and the function
Code:
#include <stdio.h>
int counting(int sick, int aCount, int bCount, int cCount, int dCount, int eCount)
{
if (sick >= 85) {aCount++;}
else if(sick >= 70) {bCount++;}
else if(sick >= 60) {cCount++;}
else if(sick >= 55) {dCount++;}
else {eCount++;}
}
char score2grade(int score)
{
if (score >=85) return 'A';
else if(score >=70) return 'B';
else if(score >= 60) return 'C';
else if(score >= 55) return 'D';
else return 'E';
}
int average(int avg, int total)
{
avg = total/10;
}
If you can help me a little I'll appreciate it.
Thanks in advance.