帮帮忙啊!!C语言!!

来源:百度知道 编辑:UC知道 时间:2024/05/25 12:48:06
帮帮忙啊!!C语言!!

1.编写程序,从键盘输入某宿舍楼6家住户某鱼的水电消耗量及水费和电费标准,计算各户应缴纳的水费和电费.数据要求如下:
(1)水费的标准为:1.5元/吨,电费标准为:0.5元/度,6户人家的信息如表一所示
将表一中信息按下面格式组织在文件input.dat中:
1.5 0.5
101 5 150
201 4 90
301 4 120
401 3 78
501 5 60
601 6 105
要求程序从文件input.dat中读取上述数据.
(2)分别计算每户应交的电费、水费以及电费和水费的总和.
(3)汇总全部住户水费、电费的总和.
(4)将计算结果按表二所示格式写入文件charge.dat中.
表格线不必输出

#include <stdlib.h>
#include <stdio.h>
#include <memory.h> /* TC 2.0 mem.h */
float waterfact, powerfact;
int counter;
typedef struct userinfo
{
long number;
int waterconsump;
int powerconsump;
} userinfo;

userinfo users[100];

void createdatafile()
{
FILE *fp;
int ws, ps;
long num;
float t1, t2;

if ((fp = fopen("input.dat", "w")) == NULL)
{
printf("打开文件失败!\n");
exit(-1);
}

printf("请输入水费的标准和电费标准(空格分开):\n");
scanf("%f %f", &t1, &t2);
fprintf(fp, "%.2f %.2f\n", t1, t2);

printf("请输入住户信息(住户地址 水耗<吨> 电耗<度>,0结束输入):\n");

while (1)
{
scanf("%ld", &num);

if (num == 0) break;

scanf("%d %d", &ws, &ps);
fprintf(fp, "%l