Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string year, type, net;
- cin >> year >> type >> net;
- int months;
- cin >> months;
- double sum = 0;
- if (type == "Small") {
- if (year == "one") {
- sum += 9.98;
- }
- else {
- sum += 8.58;
- }
- }
- else if (type == "Middle") {
- if (year == "one") {
- sum += 18.99;
- }
- else {
- sum += 17.09;
- }
- }
- else if (type == "Large") {
- if (year == "one") {
- sum += 25.98;
- }
- else {
- sum += 23.59;
- }
- }
- else if (type == "ExtraLarge") {
- if (year == "one") {
- sum += 35.99;
- }
- else{
- sum += 31.79;
- }
- }
- if (net == "yes") {
- if (sum <= 10) {
- sum += 5.50;
- }
- else if (sum > 10 && sum <= 30) {
- sum += 4.35;
- }
- else {
- sum += 3.85;
- }
- }
- double total = sum * months;
- if (year == "two") {
- total -= 3.75 * total / 100;
- }
- printf("%.2f lv.\v", total);
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string year, type, net;
- cin >> year >> type >> net;
- int months;
- cin >> months;
- double sum =
- type == "Small" ? (year == "one" ? 9.98 : 8.58) :
- type == "Middle" ? (year == "one" ? 18.99 : 17.09) :
- type == "Large" ? (year == "one" ? 25.98 : 23.59) :
- type == "ExtraLarge" ? (year == "one" ? 35.99 : 31.79) : 0;
- sum += net == "yes" ? (sum > 30 ? 3.85 : sum > 10 ? 4.35 : 5.50) : 0;
- double total = sum * months;
- if (year == "two") {
- total -= 3.75 * total / 100;
- }
- printf("%.2f lv.\v", total);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement