Home > Back-end >  The C language
The C language

Time:01-07

Task one:
Write a program to achieve:
Shops selling watermelons, more than 20 pounds per kilogram of 0.85 yuan.
Over 15 kg
Lighter than equal to 20 jins, 0.90 yuan per kilogram; Over 10 pounds lighter than equal to 15 kg, 0.95 yuan per kilogram;
Over 5 kg lighter than equal to 10 jins, 1.00 yuan per kilogram; Lighter than or equal to 5 kg, 1.05 yuan per catty,
Input watermelon and the number of customers to pay, the weight of the output and the payment should be looking for money,
Requirements: use statements for branch structure, how to write this?

CodePudding user response:



If (jin & gt; 20)
Return jin * 0.85;
Else if (jin & gt; 15 & amp; & Jin number & lt;=20)
Return jin * 0.9;
.

CodePudding user response:

Void getMoney (int kg, double money)
{
Double pay.//handle money
If (kg
=5)Pay=1.05 kg *;
Else if (kg & gt; 5 & amp; & Kg & lt;=10)
Pay=1.00 kg *;
Else if (kg & gt; 10 & amp; & Kg & lt;
=15)Pay=0.95 kg *;
Else if (kg & gt; 15 & amp; & Kg & lt;=20)
Pay=0.9 kg *;
The else
Pay=0.85 kg *;

Printf (" cope with: % f, should change: % f ", pay, money - pay);

}


Int main ()
{
GetMoney (16100);
}

CodePudding user response:

refer to the second floor Qiao Ye response:
void getMoney (int kg, double money)
{
Double pay.//handle money
If (kg
=5)Pay=1.05 kg *;
Else if (kg & gt; 5 & amp; & Kg & lt;=10)
Pay=1.00 kg *;
Else if (kg & gt; 10 & amp; & Kg & lt;
=15)Pay=0.95 kg *;
Else if (kg & gt; 15 & amp; & Kg & lt;=20)
Pay=0.9 kg *;
The else
Pay=0.85 kg *;

Printf (" cope with: % f, should change: % f ", pay, money - pay);

}


Int main ()
{
GetMoney (16100);
}

nice! Thank you for the

CodePudding user response:

reference 1st floor Chen Zhongfu response:
if (jin & gt; 20)
Return jin * 0.85;
Else if (jin & gt; 15 & amp; & Jin number & lt;=20)
Return jin * 0.9;
.

Has been done, thank you!
  • Related