Float sum of array error

Feb 21, 2014 at 8:08pm
Hi so i'm trying to build this code in visual studio where i calculate the sum of the array, among other things. However, I keep getting the error, "error C2111: '+' : pointer addition requires integral operand", but i can't figure out why. Any help would be appreciated. I'm a big newbie at this stuff.

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
  #include <stdio.h>
void change( float * const array, float *nPtr);
float sum( float * const array, int *size);

int main()
{
    int size = 10;
    float array[] = { 1, 2, 3, 5, 7, 11, 13, 17, 19, 23 };
    int j=0;
    float total;
    
    printf("\nThe size of the array is: %d\n", size);
    printf("%s\n", "List");
    
    for ( j = 0; j < size; j++) {
        printf( "%.2f\n", array[j] );
        
    }
    
    change ( array, &array[3]);
    
    printf("%s\n", "The new array is: ");
    
    for ( j = 0; j < size; j++) {
        printf( "%.2f\n", array[j] );

    }
    total = sum( array, &size);
    printf("The total is %.2f\n", total);

    
    return 0;
}
    
void change( float * const array[], float *nPtr)
{
    *nPtr = *(array[3] + 5);
    
}
float sum( float * const array[], int *size)
{
    float total = 0;
    int j = 0;
    for ( j = 0; j < *size; j++){
        
        total = total + array[j];
    }
    
    return total;
};
Feb 21, 2014 at 8:26pm
Which line are you getting the error on?
Feb 21, 2014 at 8:28pm
Line 46
Feb 21, 2014 at 8:34pm
float sum( float * const array[], int *size)

What is array supposed to be here?
Last edited on Feb 21, 2014 at 8:35pm
Feb 21, 2014 at 8:44pm
So it's supposed to take the parameters from the array and calculate the sum of it
Feb 21, 2014 at 8:45pm
That's not what my question was.
Topic archived. No new replies allowed.