- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- re:
- int a,b;
- float sum=0.0;
- cout<<"***歡迎使用電費計算機***"<<endl<<endl;
- cout<<"請輸入月份:";
- cin>>a;
- cout<<"用電度數:";
- cin>>b;
- if(a<=5&&a>0||a>=10&&a<=12)
- {
- if(b>=1001)
- {
- sum+=(b-1001+1)*5.28;
- b=1000;
- }
- if(b<=1000&&b>=701)
- {
- sum+=(b-701+1)*5.03;
- b=700;
- }
- if(b<=700&&b>=501)
- {
- sum+=(b-501+1)*4.48;
- b=500;
- }
- if(b<=500&&b>=331)
- {
- sum+=(b-331+1)*3.61;
- b=330;
- }
- if(b<=330&&b>=121)
- {
- sum+=(b-121+1)*2.68;
- b=120;
- }
- if(b<=120&&b>=0)
- {
- sum+=(b-1+1)*2.1;
- }
- }
- if(a>=6&&a<=9)
- {
- if(b>=1001)
- {
- sum+=(b-1001+1)*6.71;
- b=1000;
- }
- if(b<=1000&&b>=701)
- {
- sum+=(b-701+1)*6.16;
- b=700;
- }
- if(b<=700&&b>=501)
- {
- sum+=(b-501+1)*5.44;
- b=500;
- }
- if(b<=500&&b>=331)
- {
- sum+=(b-331+1)*4.39;
- b=330;
- }
- if(b<=330&&b>=121)
- {
- sum+=(b-121+1)*3.02;
- b=120;
- }
- if(b<=120&&b>=0)
- {
- sum+=(b-1+1)*2.1;
- }
- }
- cout<<endl<<"您要交的電費共:"<<sum<<"元"<<endl;
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |