0
Hello everyone! How do you guys write a program that will prompt the user input scores and will output the average? (C language)
2 Respostas
+ 4
Please share your attempt firstly, this is not a platform to give you a readymade code.
0
Im sorry, here's my attempt:
#include <stdio.h>
int main() {
int numScores;
double score, total = 0.0;
printf("Enter the number of scores: ");
scanf("%d", &numScores);
if (numScores <= 0) {
printf("Please enter a valid number of scores.\n");
return 1;
}
for (int i = 1; i <= numScores; i++) {
printf("Enter score #%d: ", i);
scanf("%lf", &score);
total += score;
}
double average = total / numScores;
printf("The average score is: %.2lf\n", average);
return 0;
}