返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int month,d;
  7.     cout<<"***歡迎來到小米的電費計算機***"<<endl;
  8.     cout<<endl;
  9.     cout<<"請輸入月份:";
  10.     cin>>month;
  11.     cout<<"用電度數:";
  12.     cin>>d;
  13.     float total=0;
  14.     if((month>=10 && month<=12)||(month>=1 && month<=5))
  15.     {
  16.         if(d<=120)
  17.         {
  18.            total = d*2.1;
  19.         }else if(d>=121 && d<=330)
  20.         {
  21.            total = 120*2.1 + (d-120)*2.68;
  22.         }else if(d>=331 && d<=500)
  23.         {
  24.            total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
  25.         }else if(d>=501 && d<=700)
  26.         {
  27.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
  28.         }else if(d>=701 && d<=1000)
  29.         {
  30.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
  31.         }else
  32.         {
  33.            total =120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
  34.         }  
  35.                   
  36.     }else
  37.     {
  38.         if(d<=120)
  39.         {
  40.            total = d*2.1;
  41.         }else if(d>=121 && d<=330)
  42.         {
  43.            total = 120*2.1 + (d-120)*3.02;
  44.         }else if(d>=331 && d<=500)
  45.         {
  46.            total = 120*2.1 + 210*3.02 + (d-330)*4.39;
  47.         }else if(d>=501 && d<=700)
  48.         {
  49.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
  50.         }else if(d>=701 && d<=1000)
  51.         {
  52.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
  53.         }else
  54.         {
  55.            total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
  56.         }
  57.     }
  58.     cout<<endl;
  59.     cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
  60.     system("pause");
  61.     return 0;
  62. }
複製代碼

TOP

返回列表