本帖最後由 張郁庭 於 2014-5-10 17:03 編輯
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int eletricity, money, month;
- cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
- re:
- cout<<"請輸入月份: ";
- cin>>month;
- if(month>=6 && month<=9)
- {
- cout<<"用電度數: ";
- cin>>eletricity;
- if(eletricity>0 && eletricity<=120)
- money=2.1*eletricity;
- else if(eletricity>=121 && eletricity<=330)
- money=2.1*120+3.02*(eletricity-120);
- else if(eletricity>=331 && eletricity<=500)
- money=2.1*120+3.02*210+4.39*(eletricity-330);
- else if(eletricity>=501 && eletricity<=700)
- money=2.1*120+3.02*210+4.39*170+4.97*(eletricity-500);
- else if(eletricity>700)
- money=2.1*120+3.02*210+4.39*170+4.97*200+5.63*(eletricity-700);
- else
- {
- cout<<"輸入錯誤"<<endl;
- goto re;
- }
- }
- else if((month>=10 && month<=12) || (month>=1 && month<=5))
- {
- cout<<"用電度數: ";
- cin>>eletricity;
- if(eletricity>0 && eletricity<=120)
- money=2.1*eletricity;
- else if(eletricity>=121 && eletricity<=330)
- money=2.1*120+2.68*(eletricity-120);
- else if(eletricity>=331 && eletricity<=500)
- money=2.1*120+2.68*210+3.61*(eletricity-330);
- else if(eletricity>=501 && eletricity<=700)
- money=2.1*120+2.68*210+3.61*170+4.01*(eletricity-500);
- else if(eletricity>700)
- money=2.1*120+2.68*210+3.61*170+4.01*200+4.5*(eletricity-700);
- else
- {
- cout<<"輸入錯誤"<<endl;
- goto re;
- }
- }
- else
- {
- cout<<"輸入錯誤"<<endl;
- goto re;
- }
- cout<<"你要繳交的電費共: "<<money<<"元!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |