I am trying to write a code that will take an input of 20 integers from the user and manipulate it to find the mean, max, min, and standard deviation. Everything I have found online says to pass an array by address, which I think I did correctly, but may be my issue.
I keep getting "Segmentation fault (core dumped)" after I enter in the 20 numbers and don't know why. I also get this warning "hw06.c:38: warning: format '%d' expects type 'int', but argument 2 has type 'int **'" and I don't know how to fix that either.
After these errors are fixed, I don't think my loop for max/min and possible standard deviation are correct.
I have tried many different things. I finally got rid of the errors I was previously having, for not passing my array by address but I don't even know how to tackle this error. I pasted my entire code below:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SIZE 20
void getInput(int score[SIZE]);
double getMean(int *score[SIZE]);
void getCalc(int *score[SIZE], double avg);
int main()
{
int score[SIZE] = {0};
double avg;
getInput(score[SIZE]);
avg = getMean(&score[SIZE]);
getCalc(&score[SIZE], avg);
return 0;
}
void getInput(int score[SIZE])
{
int count = 0;
printf("Enter 20 integer values -> ");
for (count = 0; count < SIZE; count++)
{
scanf("%d ", &score[count]);
printf("%d", score[count]);
}
return;
}
double getMean(int* score[])
{
int count = 0;
int totalNum = 0;
double avg;
printf("\nData set as entered: ");
for (count = 0; count < SIZE; count++)
{
totalNum = totalNum + *score[count];
printf("%d, ", *score[count]);
}
avg = ((double)totalNum / 20.0);
printf("\nMean: %.2lf", avg);
return avg;
}
void getCalc(int* score[], double avg)
{
int count = 0;
double deviation;
double standard;
int max;
int min;
for (count = 0; count < SIZE; count++)
{
deviation += (*score[count] - avg);
//printf("%lf", deviation);
if (*score[count] > *score[count - 1])
{
max = *score[count];
}
else
{
min = *score[count];
}
}
standard = (double)deviation / 20.0;
printf("\nMean Deviation: %.2lf ", standard);
printf("\nRange of Values: %d, %d", min, max);
return;
}
The code should get an array of 20 values from the user, then pass it to the next function where it will print the numbers (this time separated by commas and that last one doesn't need one but I'm not sure how to get rid of that). It then needs to find the average, which was working correctly before but I have changed things since then.
Next it needs to pass the average to the standard deviation function where it calculates standard deviation (the sum of each value - average divided by 20) and finds the max/min of the array.
I am currently just getting an error.