返回列表 發帖

電費計算機 (一)

本帖最後由 陳品肇 於 2022-4-9 11:42 編輯

參考台灣電力公司所公怖的電費計算表格,設計一個計算電費的小工具,
讓使用者輸入月份,與該月份的用電度數,電腦回應該月份的電費。

                                                                               單位:  元 / 每度




  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {

  6.    cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
  7.    int month,d;
  8.    cout<<"請輸入月份: ";
  9.    cin>>month;
  10.    cout<<"用電度數: ";
  11.    cin>>d;
  12.    
  13.    // 金額總計
  14.    float total=0;

  15.    // 非夏月條件  10~12 or 1~5
  16.    if((month>=10 && month<=12)||(month>=1 && month<=5))
  17.    {
  18.        // 非夏月
  19.         if(d<=120)
  20.         {
  21.            total = d*2.1;
  22.         }else if(d>=121 && d<=330)
  23.         {
  24.            total = 120*2.1 + (d-120)*2.68;
  25.         }else if(d>=331 && d<=500)
  26.         {
  27.            total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
  28.         }else if(d>=501 && d<=700)
  29.         {
  30.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
  31.         }else if(d>=701 && d<=1000)
  32.         {
  33.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
  34.         }else
  35.         {
  36.            total =120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
  37.         }  
  38.    }else
  39.    {
  40.         // 夏月
  41.         if(d<=120)
  42.         {
  43.            total = d*2.1;
  44.         }else if(d>=121 && d<=330)
  45.         {
  46.            total = 120*2.1 + (d-120)*3.02;
  47.         }else if(d>=331 && d<=500)
  48.         {
  49.            total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
  50.         }else if(d>=501 && d<=700)
  51.         {
  52.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
  53.         }else if(d>=701 && d<=1000)
  54.         {
  55.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
  56.         }else
  57.         {
  58.            total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
  59.         }
  60.    }
  61.    
  62.    cout<<endl;
  63.    cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
  64.    system("pause");
  65.    return 0;
  66. }
複製代碼
進階補充程式方法二:
  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {

  6.    cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
  7.    int month,d;
  8.    cout<<"請輸入月份: ";
  9.    cin>>month;
  10.    cout<<"用電度數: ";
  11.    cin>>d;
  12.    
  13.    // 金額總計
  14.    float total=0;
  15.    // 預設陣列都是 夏月的係數
  16.    float arr[]={2.1,3.02,4.39,5.44,6.16,6.71};

  17.    // 非夏月條件  10~12 or 1~5
  18.    if((month>=10 && month<=12)||(month>=1 && month<=5))
  19.    {
  20.        // 把預設係數換成非夏月
  21.        arr[0]=2.1;
  22.        arr[1]=2.68;
  23.        arr[2]=3.61;
  24.        arr[3]=4.48;
  25.        arr[4]=5.03;
  26.        arr[5]=5.28;
  27.    }
  28.         
  29.         if(d<=120)
  30.         {
  31.            total = d*arr[0];
  32.         }else if(d>=121 && d<=330)
  33.         {
  34.            total = 120*arr[0] + (d-120)*arr[1];
  35.         }else if(d>=331 && d<=500)
  36.         {
  37.            total = 120*arr[0] + (330-120)*arr[1] + (d-330)*arr[2];
  38.         }else if(d>=501 && d<=700)
  39.         {
  40.            total = 120*arr[0] +(330-120)*arr[1]+(500-330)*arr[2]+(d-500)*arr[3];
  41.         }else if(d>=701 && d<=1000)
  42.         {
  43.            total = 120*arr[0]+(330-120)*arr[1]+(500-330)*arr[2]+(700-500)*arr[3]+(d-700)*arr[4];
  44.         }else
  45.         {
  46.            total =120*arr[0]+(330-120)*arr[1]+(500-330)*arr[2]+(700-500)*arr[3]+(1000-700)*arr[4]+(d-1000)*arr[5];
  47.         }
  48.    
  49.    
  50.    cout<<endl;
  51.    cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
  52.    system("pause");
  53.    return 0;
  54. }
複製代碼

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

TOP

  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

提示: 作者被禁止或刪除 內容自動屏蔽

TOP

提示: 作者被禁止或刪除 內容自動屏蔽

TOP

  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

  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {

  6.    cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
  7.    int month,d;
  8.    cout<<"請輸入月份: ";
  9.    cin>>month;
  10.    cout<<"用電度數: ";
  11.    cin>>d;
  12.    
  13.    // 金額總計
  14.    float total=0;

  15.    // 非夏月條件  10~12 or 1~5
  16.    if((month>=10 && month<=12)||(month>=1 && month<=5))
  17.    {
  18.        // 非夏月
  19.         if(d<=120)
  20.         {
  21.            total = d*2.1;
  22.         }else if(d>=121 && d<=330)
  23.         {
  24.            total = 120*2.1 + (d-120)*2.68;
  25.         }else if(d>=331 && d<=500)
  26.         {
  27.            total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
  28.         }else if(d>=501 && d<=700)
  29.         {
  30.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
  31.         }else if(d>=701 && d<=1000)
  32.         {
  33.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
  34.         }else
  35.         {
  36.            total =120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
  37.         }  
  38.    }else
  39.    {
  40.         // 夏月
  41.         if(d<=120)
  42.         {
  43.            total = d*2.1;
  44.         }else if(d>=121 && d<=330)
  45.         {
  46.            total = 120*2.1 + (d-120)*3.02;
  47.         }else if(d>=331 && d<=500)
  48.         {
  49.            total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
  50.         }else if(d>=501 && d<=700)
  51.         {
  52.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
  53.         }else if(d>=701 && d<=1000)
  54.         {
  55.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
  56.         }else
  57.         {
  58.            total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
  59.         }
  60.    }
  61.    
  62.    cout<<endl;
  63.    cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
  64.    system("pause");
  65.    return 0;
  66. }
複製代碼

TOP

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

TOP

  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {

  6.    cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
  7.    int month,d;
  8.    cout<<"請輸入月份: ";
  9.    cin>>month;
  10.    cout<<"用電度數: ";
  11.    cin>>d;
  12.    
  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.    }else
  36.    {
  37.         if(d<=120)
  38.         {
  39.            total = d*2.1;
  40.         }else if(d>=121 && d<=330)
  41.         {
  42.            total = 120*2.1 + (d-120)*3.02;
  43.         }else if(d>=331 && d<=500)
  44.         {
  45.            total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
  46.         }else if(d>=501 && d<=700)
  47.         {
  48.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
  49.         }else if(d>=701 && d<=1000)
  50.         {
  51.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
  52.         }else
  53.         {
  54.            total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
  55.         }
  56.    }
  57.    
  58.    cout<<endl;
  59.    cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
  60.    system("pause");
  61.    return 0;
  62. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {  
  7.     int month=0,d=0;
  8.     float total=0;
  9.     cout<<"***歡迎使用小米的電費計機***"<<endl;
  10.     cout<<"輸入月份:";
  11.     cin>>month;  
  12.     cout<<"用電度數";
  13.     cin>>d;
  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.     }else
  36.     {
  37. if(d<=120)
  38.         {
  39.            total = d*2.1;
  40.         }else if(d>=121 && d<=330)
  41.         {
  42.            total = 120*2.1 + (d-120)*3.02;
  43.         }else if(d>=331 && d<=500)
  44.         {
  45.            total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
  46.         }else if(d>=501 && d<=700)
  47.         {
  48.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
  49.         }else if(d>=701 && d<=1000)
  50.         {
  51.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
  52.         }else
  53.         {
  54.            total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
  55.         }
  56.     }
  57.     cout<<"總計:"<<total<<endl;
  58.     system("pause");  
  59.     return 0;   
  60. }
複製代碼

TOP

  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.         cout<<endl;
  14.         float total=0;
  15.         if((month>=10 && month<=12)||(month>=1 && month<=5))
  16.    {
  17.         if(d<=120)
  18.         {
  19.            total = d*2.1;
  20.         }else if(d>=121 && d<=330)
  21.         {
  22.            total = 120*2.1 + (d-120)*2.68;
  23.         }else if(d>=331 && d<=500)
  24.         {
  25.            total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
  26.         }else if(d>=501 && d<=700)
  27.         {
  28.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
  29.         }else if(d>=701 && d<=1000)
  30.         {
  31.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
  32.         }else
  33.         {
  34.            total =120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
  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 + (330-120)*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.    
  59.    cout<<endl;
  60.         cout<<"您要繳交的電費共:"<<total<<"元!";
  61.      system("pause");
  62.      return 0;
  63. }
複製代碼

TOP

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

TOP

  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {

  6.    cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
  7.    int month,d;
  8.    cout<<"請輸入月份: ";
  9.    cin>>month;
  10.    cout<<"用電度數: ";
  11.    cin>>d;
  12.    
  13.    // 金額總計
  14.    float total=0;
  15.    
  16.    // 非夏月條件  10~12 or 1~5
  17.    if((month>=10 && month<=12)||(month>=1 && month<=5))
  18.    {
  19.    }else
  20.    {
  21.         // 夏月
  22.         if(d<=120)
  23.         {
  24.            total = d*2.1;
  25.         }else if(d>=121 && d<=330)
  26.         {
  27.            total = 120*2.1 + (d-120)*3.02;
  28.         }else if(d>=331 && d<=500)
  29.         {
  30.            total = 120*2.1 + 210*3.02 + (d-330)*4.39;
  31.         }else if(d>=501 && d<=700)
  32.         {
  33.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
  34.         }else if(d>=701 && d<=1000)
  35.         {
  36.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
  37.         }else
  38.         {
  39.            total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
  40.         }
  41.    }
  42.    
  43.    cout<<"總計:"<<total<<endl;
  44.    system("pause");
  45.    return 0;
  46. }
複製代碼

TOP

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

TOP

  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {

  6.    cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
  7.    int month,d;
  8.    cout<<"請輸入月份: ";
  9.    cin>>month;
  10.    cout<<"用電度數: ";
  11.    cin>>d;
  12.    
  13.    // 金額總計
  14.    float total=0;

  15.    // 非夏月條件  10~12 or 1~5
  16.    if((month>=10 && month<=12)||(month>=1 && month<=5))
  17.    {
  18.        // 非夏月
  19.         if(d<=120)
  20.         {
  21.            total = d*2.1;
  22.         }else if(d>=121 && d<=330)
  23.         {
  24.            total = 120*2.1 + (d-120)*2.68;
  25.         }else if(d>=331 && d<=500)
  26.         {
  27.            total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
  28.         }else if(d>=501 && d<=700)
  29.         {
  30.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
  31.         }else if(d>=701 && d<=1000)
  32.         {
  33.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
  34.         }else
  35.         {
  36.            total =120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
  37.         }  
  38.    }else
  39.    {
  40.         // 夏月
  41.         if(d<=120)
  42.         {
  43.            total = d*2.1;
  44.         }else if(d>=121 && d<=330)
  45.         {
  46.            total = 120*2.1 + (d-120)*3.02;
  47.         }else if(d>=331 && d<=500)
  48.         {
  49.            total = 120*2.1 + (330-120)*3.02 + (d-330)*4.39;
  50.         }else if(d>=501 && d<=700)
  51.         {
  52.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(d-500)*5.44;
  53.         }else if(d>=701 && d<=1000)
  54.         {
  55.            total = 120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(d-700)*6.16;
  56.         }else
  57.         {
  58.            total =120*2.1+(330-120)*3.02+(500-330)*4.39+(700-500)*5.44+(1000-700)*6.16+(d-1000)*6.71;
  59.         }
  60.    }
  61.    
  62.    cout<<endl;
  63.    cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
  64.    system("pause");
  65.    return 0;
  66. }
複製代碼

TOP

  1. #include<cstdlib>
  2. #include<iostream>
  3. using namespace std;
  4. int main()
  5. {

  6.    cout<<"***歡迎使用小米的電費計算機***"<<endl<<endl;
  7.    int month,d;
  8.    cout<<"請輸入月份: ";
  9.    cin>>month;
  10.    cout<<"用電度數: ";
  11.    cin>>d;
  12.    
  13.   
  14.    float total=0;

  15.    if((month>=10 && month<=12)||(month>=1 && month<=5))
  16.    {
  17.         if(d<=120)
  18.         {
  19.            total = d*2.1;
  20.         }else if(d>=121 && d<=330)
  21.         {
  22.            total = 120*2.1 + (d-120)*2.68;
  23.         }else if(d>=331 && d<=500)
  24.         {
  25.            total = 120*2.1 + (330-120)*2.68 + (d-330)*3.61;
  26.         }else if(d>=501 && d<=700)
  27.         {
  28.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(d-500)*4.48;
  29.         }else if(d>=701 && d<=1000)
  30.         {
  31.            total = 120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(d-700)*5.03;
  32.         }else
  33.         {
  34.            total =120*2.1+(330-120)*2.68+(500-330)*3.61+(700-500)*4.48+(1000-700)*5.03+(d-1000)*5.28;
  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 + (330-120)*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.    
  59.    cout<<endl;
  60.    cout<<"您要繳交電費共:"<<total<<"元!"<<endl;
  61.    system("pause");
  62.    return 0;
  63. }
複製代碼

TOP

返回列表