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;
- int overnights;
- cin >> overnights;
- double overnightPrice;
- cin >> overnightPrice;
- int additionalCosts;
- cin >> additionalCosts;
- if (overnights > 7) {
- overnightPrice *= 0.95;
- }
- budget -= overnightPrice * overnights + 0.01 * budget * additionalCosts;
- if (budget >= 0) {
- printf("Ivanovi will be left with %.2f leva after vacation.\n", budget);
- }
- else {
- printf("%.2f leva needed.\n", abs(budget));
- }
- return 0;
- }
- Решение с тернарен оператор и леко тарикатската:)
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- double budget, overnights, overnightPrice, additionalCosts;
- cin >> budget >> overnights >> overnightPrice >> additionalCosts;
- budget -= overnightPrice * (overnights > 7 ? 0.95 : 1) * overnights + 0.01 * budget * additionalCosts;
- budget >= 0 ?
- printf("Ivanovi will be left with %.2f leva after vacation.\n", budget) :
- printf("%.2f leva needed.\n", abs(budget));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement