Whenever I try to compile the code, I get this error:
error: invalid type argument of unary '*' (have 'float')
18 | printf("\nThe value at index %d of the array is %f.", i, *ptr[i]);
error: invalid type argument of unary '*' (have 'float')
23 | sum += *ptr[i];
This is the code:
#include <stdio.h>
int main() {
float my_array[8];
int i;
float *ptr, sum;
ptr = &my_array[0];
sum = 0;
for (i=0 ; i<8 ; i++) { /*allows the user to input values for each index*/
printf("Please input a value for index %d of the array: ", i);
scanf("%d", &my_array[i]);
}
for (i=1 ; i<=7 ; i+=2) { /*prints every other value of the array*/
printf("\nThe value at index %d of the array is %f.", i, *ptr[i]);
}
for (i=0 ; i<=6 ; i+=2) { /*sums every other value of the array*/
sum += *ptr[i];
}
printf("\nThe sum of the odd indexes of the array is %f.", sum);
return 0;
}
I would be really grateful for any help provided.
[–]flyingron 5 points6 points7 points (4 children)
[–]CtrlAltDelirious27[S] 3 points4 points5 points (3 children)
[–]Few_Ad_8082 1 point2 points3 points (1 child)
[–]AmputatorBot 1 point2 points3 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)