Advertisement
avr39ripe

cppTernaryOperator

Jun 14th, 2021
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     bool goodJob{ false };
  6.  
  7.     int salary{ 100 };
  8.     const int goodBonus{ 50 };
  9.     const int badBonus{ -10 };
  10.     //int bonus{0};
  11.  
  12.     std::cout << "Does job made good? yes - 1 / no - 0\n";
  13.     std::cin >> goodJob;
  14.    
  15.     //if (goodJob)
  16.     //{
  17.     //  bonus = goodBonus;
  18.     //}
  19.     //else
  20.     //{
  21.     //  bonus = badBonus;
  22.     //}
  23.  
  24.     // expr1 ? ifTrue : ifFalse
  25.     //goodJob ? bonus = goodBonus : bonus = badBonus;
  26.     //bonus =  goodJob ? goodBonus : badBonus;
  27.  
  28.     salary += goodJob ? goodBonus : badBonus;
  29.     std::cout << "Your salary is: " << salary << '\n';
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement