Advertisement
Spocoman

Beer and chips

Sep 15th, 2023
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     string name;
  9.     getline(cin, name);
  10.  
  11.     double budget, beerCount, chipsCount;
  12.     cin >> budget >> beerCount >> chipsCount;
  13.  
  14.     double beerPrice = beerCount * 1.20;
  15.     double chips = chipsCount * beerPrice * 0.45;
  16.  
  17.     double sum = beerPrice + ceil(chips);
  18.  
  19.     if (budget < sum) {
  20.         printf("%s needs %.2f more leva!\n", name.c_str(), sum - budget);
  21.     }
  22.     else {
  23.         printf("%s bought a snack and has %.2f leva left.\n", name.c_str(), budget - sum);
  24.     }
  25.  
  26.     return 0;
  27. }
  28.  
  29. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР И ЛЕКО ТАРИКАТСКАТА:)
  30.  
  31. #include <iostream>
  32. #include <string>
  33. #include <cmath>
  34.  
  35. using namespace std;
  36.  
  37. int main() {
  38.     string name;
  39.     getline(cin, name);
  40.  
  41.     double budget, beerCount, chipsCount;
  42.     cin >> budget >> beerCount >> chipsCount;
  43.  
  44.     budget -= beerCount * 1.2 + ceil(beerCount * 1.2 * chipsCount * 0.45);
  45.  
  46.     budget < 0 ?
  47.         printf("%s needs %.2f more leva!\n", name.c_str(), abs(budget)) :
  48.         printf("%s bought a snack and has %.2f leva left.\n", name.c_str(), budget);
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement