Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- double budget;
- cin >> budget;
- string destination, season;
- cin >> destination >> season;
- int days;
- cin >> days;
- double daySum = 0;
- if (destination == "Dubai") {
- if (season == "Winter") {
- daySum = 45000;
- }
- else {
- daySum = 40000;
- }
- daySum *= 0.70;
- }
- else if (destination == "Sofia") {
- if (season == "Winter") {
- daySum = 17000;
- }
- else {
- daySum = 12500;
- }
- daySum *= 1.25;
- }
- else {
- if (season == "Winter") {
- daySum = 24000;
- }
- else {
- daySum = 20250;
- }
- }
- double totalSum = daySum * days;
- if (totalSum <= budget) {
- printf("The budget for the movie is enough! We have %.2f leva left!\n", budget - totalSum);
- }
- else {
- printf("The director needs %.2f leva more!\n", totalSum - budget);
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- double budget;
- cin >> budget;
- string destination, season;
- cin >> destination >> season;
- int days;
- cin >> days;
- budget -=
- (destination == "Dubai" ? (season == "Winter" ? 45000 : 40000) * 0.70 :
- destination == "Sofia" ? (season == "Winter" ? 17000 : 12500) * 1.25 :
- (season == "Winter" ? 24000 : 20250)) * days;
- budget >= 0 ?
- printf("The budget for the movie is enough! We have %.2f leva left!\n", budget) :
- printf("The director needs %.2f leva more!\n", abs(budget));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement