本帖最後由 陳品肇 於 2019-1-12 17:23 編輯
參考台灣電力公司所公怖的電費計算表格, 設計一個計算電費的小工具,
讓使用者輸入月份, 與該月份的用電度數, 電腦回應該月份的電費.
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- int degree,month;
- float money;
- cout<<"*** 電費計算機 ***"<<endl<<endl;
- cout<<"請輸入月份: ";
- cin>>month;
- if(month>=6 && month<=9)
- {
- cout<<"用電度數: ";
- cin>>degree;
- if(degree>0 && degree<=120)
- {
- money=1.63*degree;
- }else if(degree>120 && degree<=330)
- {
- money=1.63*120+2.38*(degree-120);
- }else if(degree>330 && degree<=500)
- {
- money=1.63*120+2.38*(330-120)+3.52*(degree-330);
- }else if(degree>500 && degree<=700)
- {
- money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(degree-500);
- }else if(degree>700 && degree<=1000)
- {
- money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(degree-700);
- }else if(degree>=1001)
- {
- money=1.63*120+2.38*(330-120)+3.52*(500-330)+4.8*(700-500)+5.66*(1000-700)+6.41*(degree-1000);
- }else
- {
- cout<<"用電度數輸入錯誤!"<<endl;
- system("pause");
- goto re;
- }
- }else if((month>=10 && month<=12)||(month>=1 && month<=5))
- {
- cout<<"用電度數: ";
- cin>>degree;
- if(degree>0 && degree<=120)
- {
- money=1.63*degree;
- }else if(degree>120 && degree<=330)
- {
- money=1.63*120+2.1*(degree-120);
- }else if(degree>330 && degree<=500)
- {
- money=1.63*120+2.1*(330-120)+2.89*(degree-330);
- }else if(degree>500 && degree<=700)
- {
- money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(degree-500);
- }else if(degree>700 && degree<=1000)
- {
- money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(degree-700);
- }else if(degree>=1001)
- {
- money=1.63*120+2.1*(330-120)+2.89*(500-330)+3.94*(700-500)+4.6*(1000-700)+5.03*(degree-1000);
- }else
- {
- cout<<"用電度數輸入錯誤!"<<endl;
- system("pause");
- goto re;
- }
- }else
- {
- cout<<"月份輸入錯誤!"<<endl;
- system("pause");
- goto re;
- }
- cout<<endl<<"您要繳交的電費共 "<<money<<"元!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |