Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- string month;
- cin >> month;
- int night;
- cin >> night;
- double apartmentPrice;
- double studioPrice;
- if (month == "May" || month == "October") {
- apartmentPrice = 65;
- studioPrice = 50;
- if (night > 7 && night <= 14) {
- studioPrice *= 0.95;
- }
- else if (night > 14) {
- studioPrice *= 0.70;
- }
- }
- else if (month == "June" || month == "September") {
- apartmentPrice = 68.70;
- studioPrice = 75.20;
- if (night > 14) {
- studioPrice *= 0.80;
- }
- }
- else if (month == "July" || month == "August") {
- apartmentPrice = 77;
- studioPrice = 76;
- }
- if (night > 14) {
- apartmentPrice *= 0.9;
- }
- cout.setf(ios::fixed);
- cout.precision(2);
- cout << "Apartment: " << apartmentPrice * night << " lv.\n" << "Studio: " << studioPrice * night << " lv.\n";
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- string month;
- cin >> month;
- int night;
- cin >> night;
- double apartmentPrice;
- double studioPrice;
- if (month == "May" || month == "October") {
- apartmentPrice = 65;
- studioPrice = 50 * (night > 7 && night <= 14 ? 0.95 : night > 14 ? 0.70 : 1);
- }
- else if (month == "June" || month == "September") {
- apartmentPrice = 68.70;
- studioPrice = 75.20 * (night > 14 ? 0.80 : 1);
- }
- else if (month == "July" || month == "August") {
- apartmentPrice = 77;
- studioPrice = 76;
- }
- apartmentPrice *= night > 14 ? 0.90 : 1;
- cout.setf(ios::fixed);
- cout.precision(2);
- cout << "Apartment: " << apartmentPrice * night << " lv.\n" << "Studio: " << studioPrice * night << " lv.\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement