Home > Back-end >  C language programming operations for bosses!!!!! Come on!
C language programming operations for bosses!!!!! Come on!

Time:10-09

Please use if statements and switch statements to achieve the following functions:

Write a C program to input staff's wages, calculated after-tax wages, salary after tax calculation basis is as follows:
1. The salary & gt;=5000, 15% tax

2. 5000 & gt; Salary & gt;=4000, 10% tax

3. 4000 & gt; Salary & gt;=2000, 5% tax

4. Salary & lt; 2000, no deductions

CodePudding user response:

This is a reference program, through my notes to understand the program
 
#include
//function through the calculation of the if
Double byIf (double TMP) {
Double ans=0;
If (tmp> {
=5000)Ans +=(TMP - 5000) * 0.15;
TMP=5000;
}
If (tmp> {
=4000)Ans +=(TMP - 4000) * 0.1;
TMP=4000;
}
If (tmp> {
=2000)Ans +=(TMP - 2000) * 0.05;
TMP=2000;
}
Return ans.
}
//by the switch calculation function
Double bySwitch (double TMP) {
Double ans=0;
The switch (int (1000)/TMP) {
Default:
Case 9:
Case 8:
Case 7:
Case 6:
Case 5:
Ans +=(TMP - 5000) * 0.15;
TMP=5000;
Case 4:
Ans +=(TMP - 4000) * 0.1;
TMP=4000;
Case 3:
Case 2:
Ans +=(TMP - 2000) * 0.05;
TMP=2000;
Case 1:
Case 0: break;
}
Return ans.
}

Int main () {
Double TMP.
Printf (" please enter the salary: \ n ");
Lf the scanf (" % ", & amp; TMP);
Printf (" tax for: \ n ");
Printf (" % 5 lf (if calculated) \ n ", byIf (TMP));
Printf (" % 5 lf (switch) \ n ", bySwitch (TMP));
return 0;
}

CodePudding user response:

reference 1/f, no. 3 room response:
this is a reference application, through my comments to understand the program
 
#include
//function through the calculation of the if
Double byIf (double TMP) {
Double ans=0;
If (tmp> {
=5000)Ans +=(TMP - 5000) * 0.15;
TMP=5000;
}
If (tmp> {
=4000)Ans +=(TMP - 4000) * 0.1;
TMP=4000;
}
If (tmp> {
=2000)Ans +=(TMP - 2000) * 0.05;
TMP=2000;
}
Return ans.
}
//by the switch calculation function
Double bySwitch (double TMP) {
Double ans=0;
The switch (int (1000)/TMP) {
Default:
Case 9:
Case 8:
Case 7:
Case 6:
Case 5:
Ans +=(TMP - 5000) * 0.15;
TMP=5000;
Case 4:
Ans +=(TMP - 4000) * 0.1;
TMP=4000;
Case 3:
Case 2:
Ans +=(TMP - 2000) * 0.05;
TMP=2000;
Case 1:
Case 0: break;
}
Return ans.
}

Int main () {
Double TMP.
Printf (" please enter the salary: \ n ");
Lf the scanf (" % ", & amp; TMP);
Printf (" tax for: \ n ");
Printf (" % 5 lf (if calculated) \ n ", byIf (TMP));
Printf (" % 5 lf (switch) \ n ", bySwitch (TMP));
return 0;
}


Thank you very much! I go to a compiler debugging to see see!

CodePudding user response:

refer to the second floor m0_46509725 response:
Quote: reference 1/f, no. 3 room response:
this is a reference application, through my comments to understand the program
 
#include
//function through the calculation of the if
Double byIf (double TMP) {
Double ans=0;
If (tmp> {
=5000)Ans +=(TMP - 5000) * 0.15;
TMP=5000;
}
If (tmp> {
=4000)Ans +=(TMP - 4000) * 0.1;
TMP=4000;
}
If (tmp> {
=2000)Ans +=(TMP - 2000) * 0.05;
TMP=2000;
}
Return ans.
}
//by the switch calculation function
Double bySwitch (double TMP) {
Double ans=0;
The switch (int (1000)/TMP) {
Default:
Case 9:
Case 8:
Case 7:
Case 6:
Case 5:
Ans +=(TMP - 5000) * 0.15;
TMP=5000;
Case 4:
Ans +=(TMP - 4000) * 0.1;
TMP=4000;
Case 3:
Case 2:
Ans +=(TMP - 2000) * 0.05;
TMP=2000;
Case 1:
Case 0: break;
}
Return ans.
}

Int main () {
Double TMP.
Printf (" please enter the salary: \ n ");
Lf the scanf (" % ", & amp; TMP);
Printf (" tax for: \ n ");
Printf (" % 5 lf (if calculated) \ n ", byIf (TMP));
Printf (" % 5 lf (switch) \ n ", bySwitch (TMP));
return 0;
}


Thank you very much! I go to a compiler debugging to see see!

Remember to post ao
  • Related