Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- int main() {
- string name;
- getline(cin, name);
- double budget, beerCount, chipsCount;
- cin >> budget >> beerCount >> chipsCount;
- double beerPrice = beerCount * 1.20;
- double chips = chipsCount * beerPrice * 0.45;
- double sum = beerPrice + ceil(chips);
- if (budget < sum) {
- printf("%s needs %.2f more leva!\n", name.c_str(), sum - budget);
- }
- else {
- printf("%s bought a snack and has %.2f leva left.\n", name.c_str(), budget - sum);
- }
- return 0;
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР И ЛЕКО ТАРИКАТСКАТА:)
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- int main() {
- string name;
- getline(cin, name);
- double budget, beerCount, chipsCount;
- cin >> budget >> beerCount >> chipsCount;
- budget -= beerCount * 1.2 + ceil(beerCount * 1.2 * chipsCount * 0.45);
- budget < 0 ?
- printf("%s needs %.2f more leva!\n", name.c_str(), abs(budget)) :
- printf("%s bought a snack and has %.2f leva left.\n", name.c_str(), budget);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement