Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- int main() {
- double weight;
- cin >> weight;
- string service;
- cin >> service;
- int distance;
- cin >> distance;
- double standardPrice = 0;
- if (weight < 1) {
- standardPrice = 0.03;
- }
- else if (weight >= 1 && weight < 10) {
- standardPrice = 0.05;
- }
- else if (weight >= 10 && weight < 40) {
- standardPrice = 0.10;
- }
- else if (weight >= 40 && weight < 90) {
- standardPrice = 0.15;
- }
- else if (weight >= 90 && weight < 150) {
- standardPrice = 0.20;
- }
- double expressPrice = 0;
- if (service == "express") {
- if (weight < 1) {
- expressPrice = standardPrice * 0.80;
- }
- else if (weight >= 1 && weight < 10) {
- expressPrice = standardPrice * 0.40;
- }
- else if (weight >= 10 && weight < 40) {
- expressPrice = standardPrice * 0.05;
- }
- else if (weight >= 40 && weight < 90) {
- expressPrice = standardPrice * 0.02;
- }
- else if (weight >= 90 && weight < 150) {
- expressPrice = standardPrice * 0.01;
- }
- }
- double totalPrice = standardPrice * distance + expressPrice * distance * weight;
- cout << "The delivery of your shipment with weight of "
- << fixed << setprecision(3) << weight << " kg.would cost "
- << setprecision(2) << totalPrice << " lv." << endl;
- return 0;
- }
- Решение с тернарен оператор и printf():
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- double weight;
- cin >> weight;
- string service;
- cin >> service;
- int distance;
- cin >> distance;
- double standardPrice =
- weight < 1 ? 0.03 :
- weight < 10 ? 0.05 :
- weight < 40 ? 0.10 :
- weight < 90 ? 0.15 :
- weight < 150 ? 0.20 : 0;
- double expressPrice = 0;
- if (service == "express") {
- expressPrice = 1 *
- (weight < 1 ? 0.80 :
- weight < 10 ? 0.40 :
- weight < 40 ? 0.05 :
- weight < 90 ? 0.02 :
- weight < 150 ? 0.01 : 0) * standardPrice * weight;
- }
- double totalPrice = (standardPrice + expressPrice) * distance;
- printf("The delivery of your shipment with weight of %.3f kg. would cost %.2f lv.\n", weight, totalPrice);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement