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