Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- string country, souvenir, print = "";
- cin >> country >> souvenir;
- int quantity;
- cin >> quantity;
- double price = 0;
- if (country == "Argentina") {
- if (souvenir == "flags") {
- price = 3.25;
- }
- else if (souvenir == "caps") {
- price = 7.20;
- }
- else if (souvenir == "posters") {
- price = 5.10;
- }
- else if (souvenir == "stickers") {
- price = 1.25;
- }
- else {
- print = "Invalid stock!";
- }
- }
- else if (country == "Brazil") {
- if (souvenir == "flags") {
- price = 4.20;
- }
- else if (souvenir == "caps") {
- price = 8.50;
- }
- else if (souvenir == "posters") {
- price = 5.35;
- }
- else if (souvenir == "stickers") {
- price = 1.20;
- }
- else {
- print = "Invalid stock!";
- }
- }
- else if (country == "Croatia") {
- if (souvenir == "flags") {
- price = 2.75;
- }
- else if (souvenir == "caps") {
- price = 6.90;
- }
- else if (souvenir == "posters") {
- price = 4.95;
- }
- else if (souvenir == "stickers") {
- price = 1.10;
- }
- else {
- print = "Invalid stock!";
- }
- }
- else if (country == "Denmark") {
- if (souvenir == "flags") {
- price = 3.10;
- }
- else if (souvenir == "caps") {
- price = 6.50;
- }
- else if (souvenir == "posters") {
- price = 4.80;
- }
- else if (souvenir == "stickers") {
- price = 0.90;
- }
- else {
- print = "Invalid stock!";
- }
- }
- else {
- print = "Invalid country!";
- }
- if (price > 0) {
- cout << "Pepi bought " << quantity << " " << souvenir << " of " << country
- << " for " << fixed << setprecision(2) << price * quantity << " lv.\n";
- }
- else {
- cout << print << endl;
- }
- return 0;
- }
- Решение с тернарен оператор и леко тарикатската:)
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- string country, souvenir;
- cin >> country >> souvenir;
- int quantity;
- cin >> quantity;
- double price =
- country == "Argentina" ?
- (souvenir == "flags" ? 3.25 : souvenir == "caps" ? 7.20 : souvenir == "posters" ? 5.10 : souvenir == "stickers" ? 1.25 : 0) :
- country == "Brazil" ?
- (souvenir == "flags" ? 4.20 : souvenir == "caps" ? 8.50 : souvenir == "posters" ? 5.35 : souvenir == "stickers" ? 1.20 : 0) :
- country == "Croatia" ?
- (souvenir == "flags" ? 2.75 : souvenir == "caps" ? 6.90 : souvenir == "posters" ? 4.95 : souvenir == "stickers" ? 1.10 : 0) :
- country == "Denmark" ?
- (souvenir == "flags" ? 3.10 : souvenir == "caps" ? 6.50 : souvenir == "posters" ? 4.80 : souvenir == "stickers" ? 0.90 : 0) : -1; // Ако сумата е 0 - въведена е невалидна стока, а ако е -1 - невалидна държава!
- price > 0 ?
- cout << "Pepi bought " << quantity << " " << souvenir << " of " << country << " for " << fixed << setprecision(2) << price * quantity << " lv.\n" :
- cout << (price == 0 ? "Invalid stock!" : "Invalid country!") << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement