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 modelCar = "";
- string classCar = "";
- if (budget <= 100) {
- if (season == "Summer") {
- modelCar = "Cabrio";
- budget *= 0.35;
- }
- else {
- modelCar = "Jeep";
- budget *= 0.65;
- }
- classCar = "Economy class";
- }
- else if (budget <= 500) {
- if (season == "Summer") {
- modelCar = "Cabrio";
- budget *= 0.45;
- }
- else {
- modelCar = "Jeep";
- budget *= 0.80;
- }
- classCar = "Compact class";
- }
- else {
- modelCar = "Jeep";
- classCar = "Luxury class";
- budget *= 0.90;
- }
- cout << (classCar) << endl;
- cout << modelCar << " - " << 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 modelCar = "Jeep";
- string classCar = "Luxury";
- if (budget <= 100) {
- if (season == "Summer") {
- modelCar = "Cabrio";
- budget *= 0.35;
- }
- else {
- budget *= 0.65;
- }
- classCar = "Economy class";
- }
- else if (budget <= 500) {
- if (season == "Summer") {
- modelCar = "Cabrio";
- budget *= 0.45;
- }
- else {
- budget *= 0.80;
- }
- classCar = "Compact class";
- }
- else {
- classCar = "Luxury class";
- budget *= 0.90;
- }
- cout << (classCar) << endl;
- cout << modelCar << " - " << 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 modelCar = budget <= 500 ? (season == "Summer" ? "Cabrio" : "Jeep") : "Jeep";
- string classCar = budget <= 100 ? "Economy class" : budget <= 500 ? "Compact class" : "Luxury class";
- budget *=
- budget <= 100 ? (season == "Summer" ? 0.35 : 0.65) :
- budget <= 500 ? (season == "Summer" ? 0.45 : 0.80) : 0.90;
- cout << (classCar) << endl;
- cout << modelCar << " - " << fixed << setprecision(2) << budget << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement