Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string movie, pack;
- getline(cin, movie);
- cin >> pack;
- int tickets;
- cin >> tickets;
- double sum = 0;
- if (movie == "John Wick") {
- if (pack == "Drink") {
- sum = 12;
- }
- else if (pack == "Popcorn") {
- sum = 15;
- }
- else {
- sum = 19;
- }
- }
- else if (movie == "Star Wars") {
- if (pack == "Drink") {
- sum = 18;
- }
- else if (pack == "Popcorn") {
- sum = 25;
- }
- else {
- sum = 30;
- }
- }
- else if (movie == "Jumanji") {
- if (pack == "Drink") {
- sum = 9;
- }
- else if (pack == "Popcorn") {
- sum = 11;
- }
- else {
- sum = 14;
- }
- }
- if (movie == "Star Wars" && tickets >= 4) {
- sum *= 0.70;
- }
- else if (movie == "Jumanji" && tickets == 2) {
- sum *= 0.85;
- }
- printf("Your bill is %.2f leva.\n", sum * tickets);
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string movie, pack;
- getline(cin, movie);
- cin >> pack;
- int tickets;
- cin >> tickets;
- double sum =
- movie == "John Wick" ? (pack == "Drink" ? 12 : pack == "Popcorn" ? 15 : 19) :
- movie == "Star Wars" ? (pack == "Drink" ? 18 : pack == "Popcorn" ? 25 : 30) * (tickets >= 4 ? 0.70 : 1) :
- (pack == "Drink" ? 9 : pack == "Popcorn" ? 11 : 14) * (tickets == 2 ? 0.85 : 1);
- printf("Your bill is %.2f leva.\n", sum * tickets);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement