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

返回列表