1.编写程序计算电费:每月用电不超过50度, 每度0.72元; 超过50度时, 超出部分每度1.20元.

1.编写程序计算电费:每月用电不超过50度, 每度0.72元; 超过50度时, 超出部分每度1.20元.,第1张

class exprenses

{

int degree

static double f

double fun()

{

if(degree<50)

return f=degree*0.72

else return f=(degree-50)*1.20+50*0.72

}

public static void main(String[]args)

{

exprenses p=new exprenses()

p.fun()

System.out.println(f)

}

}

十分就只值这点了

#include<stdio.h>

int main()

{

int n = 2

double a = 0

printf("请输入用电度数:")

scanf("%lf", &a)

if ( a >300 )

n = 0

else

{

if ( a >200 )

n = 1

}

// shitch的参数严格来说是接受字符型的, 而case后面则应该接常量表达式, 你之前用的变量

switch( n )

{

case '0': printf ( "你应缴纳:%.2f\n" , ( a - 300 ) * 3 + 160 )

break

case '1': printf("你应缴纳:%.2f\n", ( a - 200 ) * 0.6 + 100 )

break

default:

printf("你应缴纳:%.2f\n", a * 0.5 )

}

return 0

}

望采纳w

#include <stdio.h>typedef struct message { int di int hs int hd double sf double df double total }USER typedef struct { double w double e}PRICE int main() { PRICE price USER user[6] FILE *fp1 int i,Zhs = 0,Zhd = 0 double Zsf= 0.0,Zdf = 0.0,total = 0.0 printf("请输入水费标准和电费标准:\n") scanf("%lf%lf",&price.w, &price.e) if ((fp1 = fopen("input.dat","w")) == NULL) printf("文件打开失败\n") else fprintf(fp1,"%.1lf %.1lf\n",price.w, price.e) printf("请输入6位住户地址,某月水耗(吨)和电耗(度):\n") for(i = 0i <6++i) scanf("%d%d%d",&user[i].di,&user[i].hs,&user[i].hd) for(i = 0i <6++i) fprintf(fp1,"%d %d %d\n",user[i].di,user[i].hs,user[i].hd) for(i = 0i <6++i) { user[i].sf= user[i].hs * price.w user[i].df= user[i].hd * price.e user[i].total = user[i].df + user[i].sf Zhs += user[i].hs Zhd+= user[i].hd Zsf += user[i].sf Zdf+= user[i].df total += user[i].total } if ((fp1 = fopen("charge.dat","w")) == NULL) printf("文件打开失败\n") else { fprintf(fp1,"住户地址 水耗(吨) 水费(元) 电耗(度) 电费(元) 合计(元)\n")for(i = 0i <6++i) fprintf(fp1," %d %d %.1lf %d%.1lf %.1lf\n",user[i].di,user[i].hs,user[i].sf,user[i].hd,user[i].df,user[i].total)fprintf(fp1," total") fprintf(fp1," %d %.1lf %d %.1lf %.1lf\n",Zhs,Zsf,Zhd,Zdf,total) } return 0}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8118587.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存