| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 641 人关注过本帖
标题:这个程序哪里错了? 求大神解答??????
只看楼主 加入收藏
Endless0
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-6-13
结帖率:0
收藏
已结贴  问题点数:20 回复次数:8 
这个程序哪里错了? 求大神解答??????



这个程序哪里错了? 求大神解答??????


#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;

}
搜索更多相关主题的帖子: Welcome include charge 
2013-06-13 19:24
蚕头燕尾
Rank: 10Rank: 10Rank: 10
来 自:Gryffindo
等 级:贵宾
威 望:12
帖 子:734
专家分:1546
注 册:2013-3-24
收藏
得分:7 
你总该说下出错的类型啊

不然让人怎么看。。



学习编程,为的是表达自己的思想,而不是被别人的思想所禁锢。要先明白自己想干嘛,而不要先问别人让你干嘛。               

                                                                                                                    Black Cat      Hello Tomorrow~
2013-06-13 19:41
蚕头燕尾
Rank: 10Rank: 10Rank: 10
来 自:Gryffindo
等 级:贵宾
威 望:12
帖 子:734
专家分:1546
注 册:2013-3-24
收藏
得分:0 
何况还不写注释。。


学习编程,为的是表达自己的思想,而不是被别人的思想所禁锢。要先明白自己想干嘛,而不要先问别人让你干嘛。               

                                                                                                                    Black Cat      Hello Tomorrow~
2013-06-13 19:41
Endless0
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-6-13
收藏
得分:0 
回复 2楼 蚕头燕尾
按f4时指针指在FILE*input那行
2013-06-13 21:06
S311070111
Rank: 2
等 级:论坛游民
帖 子:18
专家分:33
注 册:2013-6-13
收藏
得分:7 
程序有点长.....
2013-06-13 23:03
蚕头燕尾
Rank: 10Rank: 10Rank: 10
来 自:Gryffindo
等 级:贵宾
威 望:12
帖 子:734
专家分:1546
注 册:2013-3-24
收藏
得分:0 
只是改了一下语法和几个很明显的错误,

因为楼主始终没有说这个程序想实现什么功能,

所以没有看具体的执行效果。

可以通过编译连接了,

楼主可以先试试。

#include<stdio.h>
#include<stdlib.h>
#include<string.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;

}

学习编程,为的是表达自己的思想,而不是被别人的思想所禁锢。要先明白自己想干嘛,而不要先问别人让你干嘛。               

                                                                                                                    Black Cat      Hello Tomorrow~
2013-06-13 23:24
Endless0
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-6-13
收藏
得分:0 
可以运行,但不是我想要的结果,还是要谢谢了!
2013-06-14 19:48
浪漫横行
Rank: 4
等 级:业余侠客
威 望:1
帖 子:127
专家分:291
注 册:2013-4-30
收藏
得分:7 
学习下。。
2013-06-14 21:15
蚕头燕尾
Rank: 10Rank: 10Rank: 10
来 自:Gryffindo
等 级:贵宾
威 望:12
帖 子:734
专家分:1546
注 册:2013-3-24
收藏
得分:0 
楼主可以描述一下自己想要实现什么效果,

然后大家就能给楼主提个自己的建议,

顺便就把你的代码的问题解决了。

另外建议楼主要养成写注释的习惯~~


学习编程,为的是表达自己的思想,而不是被别人的思想所禁锢。要先明白自己想干嘛,而不要先问别人让你干嘛。               

                                                                                                                    Black Cat      Hello Tomorrow~
2013-06-15 09:09
快速回复:这个程序哪里错了? 求大神解答??????
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027720 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved