/******************************************************************************
Genesis Ojeda
Programa de promedio de notas (validación con valor absoluto) y while
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h> //abs library
int main() {
// Variable declaration
int n1, n2, n3, average, student_count, count;
char control = 'y';
while (control == 'y') {
printf("How many students need their average calculation?: ");
scanf("%d", &student_count);
count = 1;
while(count <= student_count) {
printf("Enter the three grades of student %d: ", count);
scanf("%d %d %d", &n1, &n2, &n3);
n1 = abs(n1);
n2 = abs(n2);
n3 = abs(n3);
average = (n1 + n2 + n3) / 3;
printf("Your average is: %d\n", average);
// Assign the grade based on the final score
if (average >= 90) {
printf("You have A\n");
} else if (average >= 80) {
printf("You have B\n");
} else if (average >= 70) {
printf("You have C\n");
} else if (average >= 60) {
printf("You have D\n");
} else {
printf("You have F\n");
}
count = count + 1;
}
printf("Do you want to restart the program? (y/n): ");
scanf(" %c", &control);
while (control != 'y' && control != 'n') {
printf("Please, enter 'y' o 'n': ");
scanf(" %c", &control);
}
}
return 0;
}