Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int personCount;
- cin >> personCount;
- string season;
- cin >> season;
- double personPrice = 0;
- if (season == "spring") {
- if (personCount <= 5) {
- personPrice = 50.00;
- }
- else {
- personPrice = 48.00;
- }
- }
- else if (season == "summer") {
- if (personCount <= 5) {
- personPrice = 48.50;
- }
- else {
- personPrice = 45.00;
- }
- }
- else if (season == "autumn")
- {
- if (personCount <= 5) {
- personPrice = 60.00;
- }
- else {
- personPrice = 49.50;
- }
- }
- else {
- if (personCount <= 5) {
- personPrice = 86.00;
- }
- else {
- personPrice = 85.00;
- }
- }
- if (season == "summer") {
- personPrice *= 0.85;
- }
- else if (season == "winter") {
- personPrice *= 1.08;
- }
- printf("%.2f leva.", personPrice * personCount);
- return 0;
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int personCount;
- cin >> personCount;
- string season;
- cin >> season;
- double personPrice =
- season == "spring" ? (personCount <= 5 ? 50.00 : 48.00) :
- season == "summer" ? (personCount <= 5 ? 48.50 : 45.00) :
- season == "autumn" ? (personCount <= 5 ? 60.00 : 49.50) :
- (personCount <= 5 ? 86.00 : 85.00);
- personPrice *= season == "summer" ? 0.85 : season == "winter" ? 1.08 : 1;
- printf("%.2f leva.", personPrice * personCount);
- return 0;
- }
- ИЛИ:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int personCount;
- cin >> personCount;
- string season;
- cin >> season;
- double personPrice =
- season == "spring" ? (personCount <= 5 ? 50.00 : 48.00) :
- season == "summer" ? (personCount <= 5 ? 48.50 : 45.00) * 0.85:
- season == "autumn" ? (personCount <= 5 ? 60.00 : 49.50) :
- (personCount <= 5 ? 86.00 : 85.00) * 1.08;
- printf("%.2f leva.", personPrice * personCount);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement