Home > Blockchain >  The for loop loops only once and some variables are getting wierd numbers
The for loop loops only once and some variables are getting wierd numbers

Time:02-12

I made this program for percentages. You enter percentages one by one and it calculates the average after each input. It calculates the jump between percentages, the overall jump, the sum of all percentages(Score gotten), and the percentage of the total score(If all the percentages were 100). The problem is that it runs the for loop only once; the jumps between the averages are weird numbers. When there are 4 iterations the variables that were previously ok at lesser iterations also start to get weird numbers.

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
    int A;
    printf("Enter how many numbers are there: ");
    scanf("%d", &A);
    int C[A   1], E[A   1], F[A   1];
    int B, D;
    for(B = 1; B <= A; B  )
    {
        printf("Enter a number. This statement will loop %d times: ", A);
        scanf("%d", &C[B]);
        for(D = 1; D <= B; D  )
        {
            C[0] = C[0]   C[D];
            E[0] = C[0]   C[D - 1];
        }
        E[B] = C[0] / B;
        E[0] = E[0] / (B - 1);
        F[B] = E[B] - E[0];
    }
    F[0] = E[A] - C[1];
    E[0] = (C[0] * 100)/ (100 * A);
    for(B = 1; B <= A; B  )
    {
        printf("Your score: %d,      Your average up to here: %d,      Increase/Decrease in 
        average: %d\n", C[B], E[B], F[B]);
    }
    printf("Your overall jump/fall in average: %d,          your total score: %d,       The 
    percentage you got: %d", F[0], C[0], E[0]);
    return 0;
}

CodePudding user response:

well you have a division by zero

E[0] = E[0] / (B - 1);

when b = 1. I am sure you get an error message telling you that

  • Related