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

TOP

返回列表