Home > Back-end >  How do x in the following procedure should be assignment, to output the results right!!!!!
How do x in the following procedure should be assignment, to output the results right!!!!!

Time:10-03

This is a bonus calculation problem!
Titled: profit is less than 100000, to 10%, more than 100000 less than 200000, up 7.5%, more than 200000 less than 400000, up 5%, input profit, output bonus! I write, where x for bonuses, y for profit, but I don't know how to assign x! Because c language rules if ~ the else statement to give a variable assignment before judgment, is given x assignment for constant or can be directly calculated worth the expression, no matter how much profit the input, the output of x will assign the value or the value of the expression. Continuous try along while, also failed to find the right methods, is having a lot of headaches! I what a great god can be glad! Thank you very much!!!!!! The other, I am beginner c less than half! Haven't learned program! Don't know who look for help! So we have to post here! Please save!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CodePudding user response:

Seriously, did not understand what you mean,,, x does not need to assign a value, it is through the input of y calculated,

CodePudding user response:

X does not need to input, and you have less last else (a default value or less), such as all branches are not satisfied, that x has no value,
And print format is wrong, just like you to print a length, so the print results not
In addition, the calculation formula of you wrong?
Int main ()
{
Float x=0.0 f, y;//here or to assign an initial value x
Scans (" % f ", & amp; Y);
If (y
=100000){
X=y * 0.1 f;
}
Else if (y> 100000 & amp; & Y
=200000){
X= 100000 * 0.1 + f (y - 100000) * 0.075 f;//100000 part should be fixed, not use y by 0.1?
}
Else if (y> 200000 & amp; & Y
=400000){
X=100000 + 100000 * 0.075 * 0.1 f + f (y - 200000) * 0.05;
}
Esle
{
X=0.0 f;//or add a else branch here to assign a default value x
}
Printf (" %. 0 f ", x);//print format, here give you keep to the integer part
return 0;
}

CodePudding user response:

Less scan_s one parameter, you the corresponding parameters should be the scanf function

CodePudding user response:

refer to the second floor qybao response:
x do not need to input, and you have less the last one else (a default value or less), such as all branches are not satisfied, that x has no value,
And print format is wrong, just like you to print a length, so the print results not
In addition, the calculation formula of you wrong?
Int main ()
{
Float x=0.0 f, y;//here or to assign an initial value x
Scans (" % f ", & amp; Y);
If (y
=100000){
X=y * 0.1 f;
}
Else if (y> 100000 & amp; & Y
=200000){
X= 100000 * 0.1 + f (y - 100000) * 0.075 f;//100000 part should be fixed, not use y by 0.1?
}
Else if (y> 200000 & amp; & Y
=400000){
X=100000 + 100000 * 0.075 * 0.1 f + f (y - 200000) * 0.05;
}
Esle
{
X=0.0 f;//or add a else branch here to assign a default value x
}
Printf (" %. 0 f ", x);//print format, here give you keep to the integer part
return 0;
}

10% below 100000, refers to the profit value out of money! Not below 100000, all in 100000 as a benchmark, calculate bonus!

CodePudding user response:

refer to the second floor qybao response:
x do not need to input, and you have less the last one else (a default value or less), such as all branches are not satisfied, that x has no value,
And print format is wrong, just like you to print a length, so the print results not
In addition, the calculation formula of you wrong?
Int main ()
{
Float x=0.0 f, y;//here or to assign an initial value x
Scans (" % f ", & amp; Y);
If (y
=100000){
X=y * 0.1 f;
}
Else if (y> 100000 & amp; & Y
=200000){
X= 100000 * 0.1 + f (y - 100000) * 0.075 f;//100000 part should be fixed, not use y by 0.1?
}
Else if (y> 200000 & amp; & Y
=400000){
X=100000 + 100000 * 0.075 * 0.1 f + f (y - 200000) * 0.05;
}
Esle
{
X=0.0 f;//or add a else branch here to assign a default value x
}
Printf (" %. 0 f ", x);//print format, here give you keep to the integer part
return 0;
}

But still thanks a lot!

CodePudding user response:

refer to the second floor qybao response:
x do not need to input, and you have less the last one else (a default value or less), such as all branches are not satisfied, that x has no value,
And print format is wrong, just like you to print a length, so the print results not
In addition, the calculation formula of you wrong?
Int main ()
{
Float x=0.0 f, y;//here or to assign an initial value x
Scans (" % f ", & amp; Y);
If (y
=100000){
X=y * 0.1 f;
}
Else if (y> 100000 & amp; & Y
=200000){
X= 100000 * 0.1 + f (y - 100000) * 0.075 f;//100000 part should be fixed, not use y by 0.1?
}
Else if (y> 200000 & amp; & Y
=400000){
X=100000 + 100000 * 0.075 * 0.1 f + f (y - 200000) * 0.05;
}
Esle
{
X=0.0 f;//or add a else branch here to assign a default value x
}
Printf (" %. 0 f ", x);//print format, here give you keep to the integer part
return 0;
}

But did little to limit y> A branch of 4000000! Thank you for your guidance! To tell the truth, just afraid of a person there could not!
  • Related