I've been struggling with a couple of issues trying to get my program to properly display the correct values inputted. The program is supposed to operate by taking the average number of inputs, and display the average, highest, and lowest inputs. I'm not sure if the issue is due to the C4133 and C4244 warnings (which I will bold) or if my pointer and array setups are incorrect. The average, highest, and lowest functions are setup the same way, so I've omitted the program to just include the average function.
#include <stdio.h>
#include <stdlib.h>
void input (int *arrayptr, int num);
double calculate_average (double [], int num);
void display_results (double);
/* Main Program */
int main ()
{
int * arrayptr; /* Space to be allocated */
int entry;
int average;
explanation ();
printf ("How many entries do you wish to enter:");
scanf_s ("%d", &entry);
printf ("\n");
/* Allocates Memory for the Array*/
arrayptr = (int *)malloc(entry *sizeof(int));
if (arrayptr == NULL) {
printf (" There is not enough memory avaliable.\n");
return 1;
}
input (arrayptr, entry);
/* Initiators for calculations */
average= calculate_average (arrayptr, entry); C4133 and C4244 warning
display_results (average);
/* Frees Memory allocated for the Array*/
free((void *) arrayptr);
return 0;
}
/* Input Function */
void input ( int *arrayptr, int num)
{
int x;
for(x=0;x<=(num -1);x++)
{
printf ("Please enter value %d:", x+1);
scanf_s ("%lf", &arrayptr[x]);
printf ("\n");
}
}
/* Calculate Average Function */
double calculate_average (double d[], int num)
{
double average, total=0;
int x;
for(x=0;x<=(num -1);x++)
{
total += d[num];
}
average = total/num;
return average;
}
/* Display Results Function */
void display_results (double x)
{
printf ("The average of your entries is: %10.2f\n\n", x);
}