I'm trying to accept doubles from a text file called pay.txt. But it only seems to work with ints. When I change my var types to doubles, It creates an endless loop. Here is my code:
#include<stdio.h>
main(){
double pay_arr[5], sum;
double avg, pay, x;
FILE *inpay;
inpay = fopen("pay.txt", "r");
sum = 0;
for(x=0; x<6; x++){
while( fscanf(inpay,"%d ", &pay_arr[x]) != EOF){
printf("%d\n", pay_arr[x]);
sum = sum + pay_arr[x];
}
}
printf("total: %.2lf\n avg: %.2lf\n", sum, sum/6);
}