Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string movieName,typeOfHall;
- getline(cin, movieName);
- getline(cin, typeOfHall);
- int ticketCount;
- cin >> ticketCount;
- double ticketPrice = 0;
- if (movieName == "A Star Is Born") {
- if (typeOfHall == "normal") {
- ticketPrice = 7.50;
- }
- else if (typeOfHall == "luxury") {
- ticketPrice = 10.50;
- }
- else if (typeOfHall == "ultra luxury") {
- ticketPrice = 13.50;
- }
- }
- else if (movieName == "Bohemian Rhapsody") {
- if (typeOfHall == "normal"){
- ticketPrice = 7.35;
- }
- else if (typeOfHall == "luxury") {
- ticketPrice = 9.45;
- }
- else if (typeOfHall == "ultra luxury") {
- ticketPrice = 12.75;
- }
- }
- else if (movieName == "Green Book") {
- if (typeOfHall == "normal") {
- ticketPrice = 8.15;
- }
- else if (typeOfHall == "luxury") {
- ticketPrice = 10.25;
- }
- else if (typeOfHall == "ultra luxury") {
- ticketPrice = 13.25;
- }
- }
- else if (movieName == "The Favourite") {
- if (typeOfHall == "normal") {
- ticketPrice = 8.75;
- }
- else if (typeOfHall == "luxury") {
- ticketPrice = 11.55;
- }
- else if (typeOfHall == "ultra luxury") {
- ticketPrice = 13.95;
- }
- }
- printf("%s -> %.2f lv.\n", movieName.c_str(), ticketPrice * ticketCount);
- return 0;
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string movieName,typeOfHall;
- getline(cin, movieName);
- getline(cin, typeOfHall);
- int ticketCount;
- cin >> ticketCount;
- double ticketPrice =
- movieName == "A Star Is Born" ? (typeOfHall == "normal" ? 7.50 : typeOfHall == "luxury" ? 10.50 : 13.50) :
- movieName == "Bohemian Rhapsody" ? (typeOfHall == "normal" ? 7.35 : typeOfHall == "luxury" ? 9.45 : 12.75) :
- movieName == "Green Book" ? (typeOfHall == "normal" ? 8.15 : typeOfHall == "luxury" ? 10.25 : 13.25) :
- movieName == "The Favourite" ? (typeOfHall == "normal" ? 8.75 : typeOfHall == "luxury" ? 11.55 : 13.95) : 0;
- printf("%s -> %.2f lv.\n", movieName.c_str(), ticketPrice * ticketCount);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement