本帖最後由 tonyh 於 2012-4-14 17:43 編輯
參考台灣電力公司所公怖的電費計算表格, 設計一個計算電費的小工具,
讓使用者輸入月份, 與該月份的用電度數, 電腦回應該月份的電費.- #include<iostream>
- using namespace std;
- int main()
- {
- int month, degree, bill;
- cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
- start1:
- cout<<"請輸入月份: ";
- cin>>month;
- switch(month)
- {
- case 6: case 7: case 8: case 9:
- start2:
- cout<<"請輸入該月份的用電度數: ";
- cin>>degree;
- if(degree>700)
- {
- bill=(degree-700)*5.1+(700-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
- }else if(degree>500 && degree<=700)
- {
- bill=(degree-500)*4.51+(500-330)*4.05+(330-110)*3.02+110*2.1;
- }else if(degree>330 && degree<=500)
- {
- bill=(degree-330)*4.05+(330-110)*3.02+110*2.1;
- }else if(degree>110 && degree<=330)
- {
- bill=(degree-110)*3.02+110*2.1;
- }else if(degree>0 && degree<=110)
- {
- bill=degree*2.1;
- }else
- {
- cout<<"用電度數輸入錯誤!"<<endl;
- goto start2;
- }
- break;
- case 1: case 2: case 3: case 4: case 5: case 10: case 11: case 12:
- start3:
- cout<<"請輸入該月份的用電度數: ";
- cin>>degree;
- if(degree>700)
- {
- bill=(degree-700)*3.97+(700-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
- }else if(degree>500 && degree<=700)
- {
- bill=(degree-500)*3.55+(500-330)*3.27+(330-110)*2.68+110*2.1;
- }else if(degree>330 && degree<=500)
- {
- bill=(degree-330)*3.27+(330-110)*2.68+110*2.1;
- }else if(degree>110 && degree<=330)
- {
- bill=(degree-110)*2.68+110*2.1;
- }else if(degree>0 && degree<=110)
- {
- bill=degree*2.1;
- }else
- {
- cout<<"用電度數輸入錯誤!"<<endl;
- goto start3;
- }
- break;
- default:
- cout<<"月份輸入錯誤!"<<endl;
- goto start1;
- }
- cout<<"您"<<month<<"月份的電份總共是"<<bill<<"元!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |