Enter the weight of the goods and the transportation distance to automatically calculate the total freight

Source: Internet
Author: User

The Transportation Company calculates the freight for the user. the longer the distance, the lower the freight rate per kilometer. the basic freight per kilometer per ton is P = 3, the weight is W, the distance is S, the discount is d, the formula for calculating total freight F is f = p * w * S * (1-D ). The discount rules are as follows:
S <250 km no discount
250 <S <500 2% discount
500 <S <1000 5% discount
1000 <S <2000 8% discount
2000 <S <3000 10% discount
3000 <s 15% discount
Please write a program to automatically calculate the total freight when the user informs the weight of the goods and the distance between transportation.

 

 

# Include <stdio. h>
Void main ()
{
Double P = 3;
Double W, S, D, F;
Printf ("Enter the cargo weight and transportation distance (separated by a number): \ n ");
Scanf ("% lf, % lf", & W, & S );
If (s <= 250)
{
D = 0;
}
Else if (S> 250 & S <= 500)
{
D = 2/100;
}
Else if (S> 500 & S <= 1000)
{
D = 5/100;
}
Else if (S> 1000 & S <= 2000)
{
D = 8/100;
}
Else if (s >= 3000)
{
D = 15/100;
}
F = p * w * S * (1-D );
Printf ("total freight for shipping goods: %. 2lf RMB \ n", F );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.