Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- double budget;
- cin >> budget;
- string category;
- cin >> category;
- int people;
- cin >> people;
- if (people <= 4) {
- budget *= 0.25;
- }
- else if (people <= 9) {
- budget *= 0.4;
- }
- else if (people <= 24) {
- budget /= 2;
- }
- else if (people < 50) {
- budget *= 0.6;
- }
- else {
- budget *= 0.75;
- }
- if (category == "VIP") {
- budget -= 499.99 * people;
- }
- else {
- budget -= 249.99 * people;
- }
- cout.setf(ios::fixed);
- cout.precision(2);
- if (budget >= 0) {
- cout << "Yes! You have " << budget << " leva left." << endl;
- }
- else {
- cout << "Not enough money! You need " << abs(budget) << " leva." << endl;
- }
- return 0;
- }
- Решение с тернарен оператор :
- #include <iostream>
- using namespace std;
- int main() {
- double budget;
- cin >> budget;
- string category;
- cin >> category;
- int people;
- cin >> people;
- budget *=
- people <= 4 ? 0.25 :
- people <= 9 ? 0.4 :
- people <= 24 ? 0.5 :
- people < 50 ? 0.6 : 0.75;
- budget -= (category == "VIP" ? 499.99 : 249.99) * people;
- cout.setf(ios::fixed);
- cout.precision(2);
- budget >= 0 ?
- cout << "Yes! You have " << budget << " leva left." << endl :
- cout << "Not enough money! You need " << abs(budget) << " leva." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement