Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- double budget;
- cin >> budget;
- string season;
- cin >> season;
- string location = "";
- string place = "";
- if (season == "Summer") {
- location = "Alaska";
- }
- else {
- location = "Morocco";
- }
- if (budget <= 1000) {
- if (season == "Summer") {
- budget *= 0.65;
- }
- else {
- budget *= 0.45;
- }
- place = "Camp";
- }
- else if (budget <= 3000) {
- if (season == "Summer") {
- budget *= 0.8;
- }
- else {
- budget *= 0.6;
- }
- place = "Hut";
- }
- else {
- place = "Hotel";
- budget *= 0.9;
- }
- cout << location << " - " << place << " - " << fixed << setprecision(2) << budget << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- double budget;
- cin >> budget;
- string season;
- cin >> season;
- string location = season == "Summer" ? "Alaska" : "Morocco";
- string place = budget <= 1000 ? "Camp" : budget <= 3000 ? "Hut" : "Hotel";
- budget *=
- budget <= 1000 ? (season == "Summer" ? 0.65 : 0.45) :
- budget <= 3000 ? (season == "Summer" ? 0.80 : 0.60) : 0.90;
- cout << location << " - " << place << " - " << fixed << setprecision(2) << budget << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement