Home > Back-end >  Pay commission problem using a switch statement, there is no output in vs2017 but can run, to solve
Pay commission problem using a switch statement, there is no output in vs2017 but can run, to solve

Time:11-20

# include
Int main () {
Long double salary=0, basesalary=1000, appointed the=0, salesamount=0;//salary=basic salary + commission sales
Long double sum1=0, sum2=0, sum3=0;
int c;
Lf scanf_s (" % ", & amp; Salesamount);
C=salesamount/10000;
The switch (c) {
Case 0:
Salary=basesalary;
break;
Case 1:
If (c & lt; 2) {
Appointed the=(salesamount - 10000) * 0.05;
Salary=basesalary + themselves;
Sum1=themselves;
}
break;
Case 2:
Case 3:
Case 4:
If (c & lt; 5) {
Appointed the=sum1 + (salesamount - 20000) * 0.06;
Salary=basesalary + themselves;
Sum2=themselves;
}
break;
Case 5:
Case 6:
Case 7:
Case 8:
Case 9:
{
If (c & lt; 10) {
Appointed the sum2=sum1 + + (salesamount - 50000) * 0.07;
Salary=basesalary + themselves;
Sum3=themselves;
}
break;
}
Case 10: {
Appointed the sum2=sum1 + + sum3 + (salesamount - 100000) * 0.08;
Salary=basesalary + themselves;
break;
}
Printf (" salary=% lf ", salary).
return 0;
}
}//to run but no result

CodePudding user response:

The adjusted the code, you can run and as a result,

CodePudding user response:

reference 1st floor CHXCHXKKK response:
adjusted, your code can run and as a result, the

 
# define _CRT_SECURE_NO_WARNINGS
# include & lt; stdio.h>
# include & lt; stdlib.h>

Int main (void)
{
Long double salary=0, basesalary=1000, appointed the=0, salesamount=0;//salary=basic salary + commission sales
Long double sum1=0, sum2=0, sum3=0;
int c;
Lf the scanf (" % ", & amp; Salesamount);
C=salesamount/10000;
The switch (c)
{
Case 0:
Salary=basesalary;
break;
Case 1:
{
If (c & lt; 2)
{
Appointed the=(salesamount - 10000) * 0.05;
Salary=basesalary + themselves;
Sum1=themselves;
}
break;
}
Case 2:
Case 3:
Case 4:
{
If (c & lt; 5)
{
Appointed the=sum1 + (salesamount - 20000) * 0.06;
Salary=basesalary + themselves;
Sum2=themselves;
}
break;
}
Case 5:
Case 6:
Case 7:
Case 8:
Case 9:
{
If (c & lt; 10)
{
Appointed the sum2=sum1 + + (salesamount - 50000) * 0.07;
Salary=basesalary + themselves;
Sum3=themselves;
}
break;
}
Case 10:
{
Appointed the sum2=sum1 + + sum3 + (salesamount - 100000) * 0.08;
Salary=basesalary + themselves;
break;
}
}

Printf (" salary=% lf ", salary).
system("pause");
return 0;
}

CodePudding user response:

 # include 

Int main ()
{
Long double salary=0, basesalary=1000, appointed the=0, salesamount=0;//salary=basic salary + commission sales
Long double sum1=0, sum2=0, sum3=0;
int c;
//scanf_s (" % lf ", & amp; Salesamount);
Lf the scanf (" % ", & amp; Salesamount);
C=(int) (salesamount/10000);



The switch (c) {
Case 0:
Salary=basesalary;
break;
Case 1:
If (c & lt; 2) {
Appointed the=(salesamount - 10000) * 0.05;
Salary=basesalary + themselves;
Sum1=themselves;
}
break;
Case 2:
Case 3:
Case 4:
If (c & lt; 5) {
Appointed the=sum1 + (salesamount - 20000) * 0.06;
Salary=basesalary + themselves;
Sum2=themselves;
}
break;
Case 5:
Case 6:
Case 7:
Case 8:
Case 9:
{
If (c & lt; 10) {
Appointed the sum2=sum1 + + (salesamount - 50000) * 0.07;
Salary=basesalary + themselves;
Sum3=themselves;
}
break;
}
Case 10: {
Appointed the sum2=sum1 + + sum3 + (salesamount - 100000) * 0.08;
Salary=basesalary + themselves;
break;
}
//printf (" salary=% lf ", salary).
}
Printf (" salary=% Lf ", salary).
return 0;
}//can run but not the results

For your reference ~


Put the print on the switch, on the other hand, was long double % Lf, double corresponding % Lf

CodePudding user response:

The host's more appropriate to the problem with the if the else way

CodePudding user response:

references 4 building self-confidence boy reply:
the question of the building Lord using if else way more appropriate ~

Changing the scanf to scanf_s put the scanf your compiler may not support, in the same way in my (LINUX) compiler scanf_s does not support, it doesn't matter, check the difference between these two functions, especially the parameters of ~
  • Related