Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- double cash, sum;
- cin >> cash;
- string gender;
- cin >> gender;
- int age;
- cin >> age;
- string sport;
- cin >> sport;
- if (gender == "m") {
- if (sport == "Gym") {
- sum = 42;
- }
- else if (sport == "Boxing") {
- sum = 41;
- }
- else if (sport == "Yoga") {
- sum = 45;
- }
- else if (sport == "Zumba") {
- sum = 34;
- }
- else if (sport == "Dances") {
- sum = 51;
- }
- else if (sport == "Pilates") {
- sum = 39;
- }
- }
- else {
- if (sport == "Gym") {
- sum = 35;
- }
- else if (sport == "Boxing") {
- sum = 37;
- }
- else if (sport == "Yoga") {
- sum = 42;
- }
- else if (sport == "Zumba") {
- sum = 31;
- }
- else if (sport == "Dances") {
- sum = 53;
- }
- else if (sport == "Pilates") {
- sum = 37;
- }
- }
- if (age <= 19) {
- sum *= 0.8;
- }
- if (sum <= cash) {
- cout << "You purchased a 1 month pass for " << sport << ".\n";
- }
- else {
- cout << "You don't have enough money! You need $" << fixed << setprecision(2) << sum - cash << " more.\n";
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- double cash, sum;
- cin >> cash;
- string gender;
- cin >> gender;
- int age;
- cin >> age;
- string sport;
- cin >> sport;
- sum =
- (sport == "Gym" ? (gender == "m" ? 42 : 35) :
- sport == "Boxing" ? (gender == "m" ? 41 : 37) :
- sport == "Yoga" ? (gender == "m" ? 45 : 42) :
- sport == "Zumba" ? (gender == "m" ? 34 : 31) :
- sport == "Dances" ? (gender == "m" ? 51 : 53) :
- sport == "Pilates" ? (gender == "m" ? 39 : 37) : 0) * (age <= 19 ? 0.8 : 1);
- sum <= cash
- ? printf("You purchased a 1 month pass for %s.\n", sport.c_str())
- : printf("You don't have enough money! You need $%.2f more.\n", sum - cash);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement