Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string destination, cabinType;
- getline(cin, destination);
- getline(cin, cabinType);
- int overnights;
- cin >> overnights;
- double dayPrice = 0;
- if (destination == "Mediterranean") {
- if (cabinType == "standard cabin") {
- dayPrice = 27.50;
- }
- else if (cabinType == "cabin with balcony") {
- dayPrice = 30.20;
- }
- else {
- dayPrice = 40.50;
- }
- }
- else if (destination == "Adriatic") {
- if (cabinType == "standard cabin") {
- dayPrice = 22.99;
- }
- else if (cabinType == "cabin with balcony") {
- dayPrice = 25.00;
- }
- else {
- dayPrice = 34.99;
- }
- }
- else {
- if (cabinType == "standard cabin") {
- dayPrice = 23.00;
- }
- else if (cabinType == "cabin with balcony") {
- dayPrice = 26.60;
- }
- else {
- dayPrice = 39.80;
- }
- }
- double totalSum = dayPrice * 4 * overnights;
- if (overnights > 7) {
- totalSum *= 0.75;
- }
- printf("Annie's holiday in the %s sea costs %.2f lv.\n", destination.c_str(), totalSum);
- return 0;
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string destination, cabinType;
- getline(cin, destination);
- getline(cin, cabinType);
- int overnights;
- cin >> overnights;
- double dayPrice =
- destination == "Mediterranean" ?
- (cabinType == "standard cabin" ? 27.50 : cabinType == "cabin with balcony" ? 30.20 : 40.50) :
- destination == "Adriatic" ?
- (cabinType == "standard cabin" ? 22.99 : cabinType == "cabin with balcony" ? 25.00 : 34.99) :
- (cabinType == "standard cabin" ? 23.00 : cabinType == "cabin with balcony" ? 26.60 : 39.80);
- double totalSum = dayPrice * 4 * overnights * (overnights > 7 ? 0.75 : 1);
- printf("Annie's holiday in the %s sea costs %.2f lv.\n", destination.c_str(), totalSum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement