題目:企業發放的獎金根據利潤提成。利潤(I)低於或等於10萬元時,獎金可提10%;利潤高於10萬元,低於20萬元時,低於10萬元的部分按10%提成,高於10萬元的部分,可可提成7.5%;20萬到40萬之間時,高於20萬元的部分,可提成5%;40萬到60萬之間時高於40萬元的部分,可提成3%;60萬到100萬之間時,高於60萬元的部分,可提成1.5%,高於100萬元時,超過100萬元的部分按1%提成,從鍵盤輸入當月利潤I,求應發放獎金總數。ios
用宏定義定義經常使用的字符,而後用if語句判斷輸入的獎金數額進行計算:spa
1 #include <iostream> 2 using namespace std; 3 #define ten 10000 4 #define twenty 75000 5 #define forty 10000 6 void main(){ 7 long int i=0; 8 cout<<"請輸入獎金:"<<endl; 9 cin>>i; 10 if(i<=100000) 11 { 12 cout<<"你輸入的獎金小於或等於10萬"<<endl; 13 i*=0.1; 14 } 15 else 16 if(i<=200000) 17 { 18 cout<<"你輸入的獎金大於10萬<20萬"<<endl; 19 i=i-100000; 20 i*=0.075; 21 i+=ten; 22 } 23 else 24 if (i<=400000) 25 { 26 cout<<"你輸入的獎金大於20萬<40萬。"<<endl; 27 i-=200000; 28 i*=0.05; 29 i=i+ten+twenty; 30 } 31 else 32 if(i<=600000) 33 { 34 cout<<"你輸入的獎金大於40萬<60萬。"<<endl; 35 i-=400000; 36 i*=0.03; 37 i=i+forty+twenty+ten; 38 } 39 else 40 if(i<=1000000) 41 { 42 cout<<"你輸入的獎金大於40萬<100萬。"<<endl; 43 i-=600000; 44 i*=0.015; 45 i=i+forty+twenty+ten; 46 } 47 else 48 { 49 cout<<"你輸入的獎金大於100萬。"<<endl; 50 i-=1000000; 51 i*=0.01; 52 i=i+forty+twenty+ten; 53 } 54 cout<<"你應該發放的獎金金額度爲:"<<i<<"。"<<endl; 55 }