Pointer and Array display issues.

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#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);
}
Last edited on
You found the "bold" format strings but completely missed the "code" format strings. :-)

Please place your code in [code] tags.
Ah my mistake, it should be easier to read now.
Reconcile the types on lines 12, 34 & 61.

Also, it would help if you printed the warning messages. The numbers mean nothing to us that don't use the same compiler you use.
Topic archived. No new replies allowed.