本帖最後由 陳妍蓁 於 2024-8-10 15:32 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- int month,w;
- float sum=0.0;
- cout<<"***歡迎使用小米電費計算機***"<<endl<<endl;
- cout<<"請輸入月份:";
- cin>>month;
- cout<<"用電度數:";
- cin>>w;
- switch (month) {
- case 10 ... 12:
- case 1 ... 5:
- switch(w){
- case 1001 ... 50000000:
- sum=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(w-1000)*5.28;
- break;
- case 701 ... 1000:
- sum=120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(w-700)*5.03;
- break;
- case 501 ... 700:
- sum=120*2.1+(330-120)*2.68+(500-330)*3.61+(w-500)*4.48;
- break;
- case 331 ... 500:
- sum=120*2.1+(330-120)*2.68+(w-330)*3.61;
- break;
- case 121 ... 330:
- sum=120*2.1+(w-120)*2.68;
- break;
- case 1 ... 120:
- sum=w*2.1;
- default:
- cout<<"輸入錯誤"<<endl;
- }
- case 6 ... 9:
- switch(w)
- {
- case 1001 ... 50000000:
- sum=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(w-1000)*6.71;
- break;
- case 701 ... 1000:
- sum=120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(w-700)*6.16;
- break;
- case 501 ... 700:
- sum=120*2.1+(330-120)*3.02+(500-330)*4.39+(w-500)*5.44;
- break;
- case 331 ... 500:
- sum=120*2.1+(330-120)*3.02+(w-330)*4.39;
- break;
- case 121 ... 330:
- sum=120*2.1+(w-120)*3.02;
- break;
- case 1 ... 120:
- sum=w*2.1;
- break;
- default:
- cout<<"輸入錯誤"<<endl;
- }
- default:
- cout<<"輸入錯誤"<<endl;
- }
- cout<<endl<<"您要交的電費共:"<<sum<<"元"<<endl;
- system("pause");
- goto re;
- return 0;
- }
複製代碼 |