You add to pro , but it is not initialized, you do not pass values other than pro . You save the values in the addresses of the passed variables. In this case, you need to specify dereferencing pointers to get / get the value, *i and use your passed addresses directly in your method - then you do not need to specify their address again.
This works - I replaced double with float ...:
#include <stdio.h> #include <stdlib.h> void input(int *day, int *month, float *k, float *pro); int main(void){ int i,j; float k, pro; i = j = k = pro = 0; input(&i, &j, &k, &pro); printf("%f\n", pro); printf("%d : %d : %f\n", i,j,k); return 0; } void input(int *i, int *j, float *k, float *pro){ scanf("%d", i); scanf("%d", j); scanf("%f", k); printf("%d - %d - %f\n", *i,*j,*k); *pro += (*i * *j * *k); }
Conclusion:
1 2 3.5 1 - 2 - 3.500000 7.000000 1 : 2 : 3.500000
source share