Advertisement
Spocoman

06. Speed Info

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