六、若有一便利商店的工讀生月薪資可傳照下列方式計算
0~60個小時,每小時75元
61~75個小時以1.25倍計算
76個小時以上以1.75倍計算
寫一程式計算實領薪資

工讀生A 工讀生B
第一個月工作總數 57 65
第二個月工作總數 70 80

#include <cstdlib>
#include <iostream>

using namespace std;

float salary(int hours){
      if(hours>=0&&hours<=60){
      return hours*75;
      }
      else if(hours<=75){
      return hours*75+(hours-60)*1.25;
      }
      else{
      return hours*75+(hours-60)*1.25+(hours-75)*1.75;
      }
      }

int main(int argc, char *argv[])
{
    cout << "1: " << salary(57)+salary(70) << endl;
    cout << "2: " << salary(70)+salary(80) << endl;
   
    system("PAUSE");
    return EXIT_SUCCESS;
}

 

arrow
arrow
    全站熱搜

    Rick Lu 發表在 痞客邦 留言(1) 人氣()