返回列表 發帖
  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

返回列表