Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- const int MONTHS_OF_SEASON = 4;
- const double TAX_PROFIT_IN_PERCENTAGE = 0.10;
- string season;
- cin >> season;
- double kilometers;
- cin >> kilometers;
- double kilometerPrice;
- if (kilometers <= 5000) {
- if (season == "Spring" || season == "Autumn") {
- kilometerPrice = 0.75;
- }
- else if (season == "Summer") {
- kilometerPrice = 0.9;
- }
- else {
- kilometerPrice = 1.05;
- }
- }
- else if (kilometers <= 10000)
- {
- if (season == "Spring" || season == "Autumn") {
- kilometerPrice = 0.95;
- }
- else if (season == "Summer") {
- kilometerPrice = 1.10;
- }
- else {
- kilometerPrice = 1.25;
- }
- }
- else {
- kilometerPrice = 1.45;
- }
- double totalSum = kilometers * kilometerPrice * MONTHS_OF_SEASON * (1 - TAX_PROFIT_IN_PERCENTAGE);
- cout << fixed << setprecision(2) << totalSum << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- const int MONTHS_OF_SEASON = 4;
- const double TAX_PROFIT_IN_PERCENTAGE = 0.10;
- string season;
- cin >> season;
- double kilometers;
- cin >> kilometers;
- double kilometerPrice =
- kilometers <= 5000 ? (season == "Spring" || season == "Autumn" ? 0.75 : season == "Summer" ? 0.90 : 1.05) :
- kilometers <= 10000 ? (season == "Spring" || season == "Autumn" ? 0.95 : season == "Summer" ? 1.10 : 1.25) : 1.45;
- double totalSum = kilometers * kilometerPrice * MONTHS_OF_SEASON * (1 - TAX_PROFIT_IN_PERCENTAGE);
- cout << fixed << setprecision(2) << totalSum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement