这个程序哪里错了? 求大神解答??????
这个程序哪里错了? 求大神解答??????
#include "Stdio.h"
#include "stdlib.h"
#define NUM_USER 6
struct User_dat
{ char m_addr[6];
int m_water;
float m_mon_water;
int m_eletr;
float m_mon_eletr;
float m_mon_sum;
} T_User[NUM_USER],User[NUM_USER+1];
int main()
{
float T_M_PER_WAT = 0.0, T_M_PER_ELE = 0.0;
float M_PER_WAT = 0.0, M_PER_ELE = 0.0;
FILE *input, *charge;
int i;
char t[1]={0};
printf("Welcome to use this system\n");
printf("Please input the money of per water:\n");
scanf("%f",&T_M_PER_WAT);
printf("Please input the money of per eletricity:\n");
scanf("%f",&T_M_PER_ELE);
for(i = 0; i < NUM_USER; i ++)
{
printf("Please input the %d user address:\n",i+1);
gets(t);
gets(T_User[i].m_addr);
printf("Please input the water of the %d user:\n",i+1);
scanf("%d",&T_User[i].m_water);
printf("Please input the eletricity of the %d user:\n",i+1);
scanf("%d",&T_User[i].m_eletr);
}
}
input = fopen("input.dat","w");
if(input == NULL)
{
printf("cannot open input.dat\n");
exit(0);
else
{
fprintf(input,"%14.1f\t%5.1f\n",T_M_PER_WAT,T_M_PER_ELE);
for(i = 0; i < NUM_USER; i ++)
{
fprintf(input,"%14s\t%5d\t%10d\n",T_User[i].m_addr,T_User[i].m_water,T_User[i].m_eletr);
}
}
fclose(input);
input = fopen("input.dat","r");
if(input == NULL)
{
printf("cannot open input.dat\n");
exit(0);
}
else
{
fscanf(input,"%f\t%f\n",&M_PER_WAT,&M_PER_ELE);
for(i = 0; i < NUM_USER; i ++)
{
fscanf(input,"%14s\t%5d\t%10d\n",&User[i].m_addr,&User[i].m_water,&User[i].m_eletr);
User[i].m_mon_water = User[i].m_water*M_PER_WAT;
User[i].m_mon_eletr = User[i].m_eletr*M_PER_ELE;
User[i].m_mon_sum = User[i].m_mon_water+User[i].m_mon_eletr;
User[NUM_USER].m_water +=User[i].m_water;
User[NUM_USER].m_eletr += User[i].m_eletr;
User[NUM_USER].m_mon_water += User[i].m_mon_water;
User[NUM_USER].m_mon_eletr += User[i].m_mon_eletr;
User[NUM_USER].m_mon_sum += User[i].m_mon_sum;
}
strcpy(User[NUM_USER].m_addr,"Total");
}
fclose(input);
charge = fopen("charge.dat","w");
if(charge == NULL)
{
printf("cannot open input.dat\n");
exit(0);
}
else
{
fprintf(charge,"%14s\t%5s\t%13s\t\%10s\t%18s\t%11s\n","User'saddress","Water","Water'smoney","Eletricity","Eletricity's money","Total money");
for(i = 0; i < NUM_USER + 1; i ++)
{
fprintf(input,"%14s\t%5d\t%13.1f\t\%10d\t%18.1f\t%11.1f\n",User[i].m_addr,User[i].m_water,User[i].m_mon_water,User[i].m_eletr,User[i].m_mon_eletr,User[i].m_mon_sum);
}
}
fclose(charge);
return 0;
}