I am doing a basic program in C, to calculate notes. It consists of an array in which some notes read by keyboard are stored. Once they are introduced, they are added one by one and stored in a variable.
The problem is that it does not add the elements of the vector, it only saves the last one in the variable. I leave the code:
#include <stdio.h>
int main() {
int i = 0, j, sino, porcentaje, cont = 0;
float notas[10], total = 0, notaActual;
do {
printf("Escribe la nota: ");
scanf("%f", ¬aActual);
printf("Escribe el porcentaje sobre 100 de esa nota sobre la nota total: ");
scanf("%d", &porcentaje);
notas[i] = notaActual*(porcentaje*0.01);
printf("Continuar con las notas? (1/0): ");
scanf("%d", &sino);
if(sino == 1)
i++;
} while (sino == 1 && i < 10); //No es necesario llenar el vector
for(j = 0; j <= i; j++) {
total += notas[j];
printf("%f ", notas[j]);
}
printf("\nTU NOTA SOBRE 10 ES %f", &total);
return 0;
}
If we enter a 5 with 50 percentage in two iterations, the output is:
2.50 2.50
TU NOTA SOBRE 10 ES 2.50