Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- string type;
- cin >> type;
- double quantity, date;
- cin >> quantity >> date;
- double price = 0;
- if (date <= 15) {
- if (type == "Cake") {
- price = 24.00;
- }
- else if (type == "Souffle") {
- price = 6.66;
- }
- else {
- price = 12.60;
- }
- }
- else {
- if (type == "Cake") {
- price = 28.70;
- }
- else if (type == "Souffle") {
- price = 9.80;
- }
- else {
- price = 16.98;
- }
- }
- double sum = price * quantity;
- if (date <= 22) {
- if (sum >= 100 && sum <= 200) {
- sum -= sum * 0.15;
- }
- else if (sum > 200) {
- sum -= sum * 0.25;
- }
- }
- if (date <= 15) {
- sum -= sum * 0.10;
- }
- cout << fixed << setprecision(2) << sum << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- string type;
- cin >> type;
- double quantity, date;
- cin >> quantity >> date;
- double sum =
- (date <= 15 ? (type == "Cake" ? 24.00 : type == "Souffle" ? 6.66 : 12.60) :
- (type == "Cake" ? 28.70 : type == "Souffle" ? 9.80 : 16.98)) * quantity;
- sum *= date <= 22 ? (sum > 200 ? 0.75 : sum >= 100 ? 0.85 : 1) : 1;
- if (date <= 15) {
- sum *= 0.90;
- }
- cout << fixed << setprecision(2) << sum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement