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