Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string fruit, fruitSize;
- cin >> fruit >> fruitSize;
- int fruitCount;
- cin >> fruitCount;
- double fruitPrice = 0;
- if (fruit == "Watermelon") {
- if (fruitSize == "small") {
- fruitPrice = 56;
- }
- else {
- fruitPrice = 28.70;
- }
- }
- else if (fruit == "Mango") {
- if (fruitSize == "small") {
- fruitPrice = 36.66;
- }
- else {
- fruitPrice = 19.60;
- }
- }
- else if (fruit == "Pineapple") {
- if (fruitSize == "small") {
- fruitPrice = 42.10;
- }
- else {
- fruitPrice = 24.80;
- }
- }
- else if (fruit == "Raspberry") {
- if (fruitSize == "small") {
- fruitPrice = 20;
- }
- else {
- fruitPrice = 15.20;
- }
- }
- if (fruitSize == "small") {
- fruitPrice *= 2;
- }
- else {
- fruitPrice *= 5;
- }
- double total = fruitPrice * fruitCount;
- if (total >= 400 && total <= 1000) {
- total *= 0.85;
- }
- else if (total > 1000) {
- total /= 2;
- }
- printf("%.2f lv.\n", total);
- return 0;
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string fruit, fruitSize;
- cin >> fruit >> fruitSize;
- int fruitCount;
- cin >> fruitCount;
- double fruitPrice =
- (fruit == "Watermelon" ? (fruitSize == "small" ? 56 : 28.70) :
- fruit == "Mango" ? (fruitSize == "small" ? 36.66 : 19.60) :
- fruit == "Pineapple" ? (fruitSize == "small" ? 42.10 : 24.80) :
- fruit == "Raspberry" ? (fruitSize == "small" ? 20 : 15.20) : 0)
- * (fruitSize == "small" ? 2 : 5);
- double total = fruitPrice * fruitCount;
- total *= total > 1000 ? 0.5 : total >= 400 ? 0.85 : 1;
- printf("%.2f lv.\n", total);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement