Advertisement
avr39ripe

BR012ternaryOpExample

Jan 26th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4.  
  5. int main()
  6. {
  7.     int grade{ 4 };
  8.     bool passExam{ false };
  9.     float studPayment{ 0 };
  10.     const float passPay{ 100 };
  11.     const float failedPay{ 20 };
  12.  
  13.     int a{ 10 };
  14.     int b{ 20 };
  15.     int c{ 30 };
  16.     int max{ 0 };
  17.  
  18.     max = a > b ? (a > c ? a : c) : (b > c ? b : c);
  19.  
  20.  
  21.  
  22.     std::cout << "Enter exam grade: \n";
  23.     std::cin >> grade;
  24.  
  25.  
  26.     //((expr) ? (exprTrue) : (exprFalse));
  27.  
  28.     //grade > 3 ? passExam = true : passExam = false;
  29.    
  30.     //passExam = (grade > 3 ? true : false);
  31.  
  32.     passExam = (grade > 3);
  33.  
  34.     studPayment = passExam ? passPay : failedPay;
  35.  
  36.     /*
  37.     *if (grade > 3)
  38.     {
  39.         passExam = true;
  40.     }
  41.     else
  42.     {
  43.         passExam = false;
  44.     }
  45.     */
  46.    
  47.  
  48.     //
  49.     return 0;
  50. }
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement