Advertisement
Spocoman

02. Bonus Score

Sep 1st, 2023 (edited)
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int number;
  7.     cin >> number;
  8.  
  9.     double bonus = 0;
  10.  
  11.     if (number <= 100) {
  12.         bonus = 5;
  13.     }
  14.     else if (number > 1000) {
  15.         bonus = number * 0.1;
  16.     }
  17.     else {
  18.         bonus = number * 0.2;
  19.     }
  20.  
  21.     if (number % 2 == 0) {
  22.         bonus++;
  23.     }
  24.     else if (number % 10 == 5) {
  25.         bonus += 2;
  26.     }
  27.  
  28.     cout << bonus << endl;
  29.     cout << bonus + number << endl;
  30.  
  31.     return 0;
  32. }
  33.  
  34. Решение с тернарен оператор:
  35.  
  36. #include <iostream>
  37.  
  38. using namespace std;
  39.  
  40. int main() {
  41.     int number;
  42.     cin >> number;
  43.  
  44.     double bonus = 0;
  45.  
  46.     bonus +=
  47.         number <= 100 ? 5 :
  48.         number > 1000 ? number * 0.1 : number * 0.2;
  49.  
  50.     bonus +=
  51.         number % 2 == 0 ? 1 :
  52.         number % 10 == 5 ? 2 : 0;
  53.  
  54.     cout << bonus << endl << bonus + number << endl;
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement