Advertisement
Spocoman

09. Weather Forecast

Sep 1st, 2023 (edited)
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {    
  6.     string weather;
  7.     cin >> weather;
  8.  
  9.     if (weather == "sunny") {
  10.         cout << "It's warm outside!" << endl;
  11.     }
  12.     else {
  13.         cout << "It's cold outside!" << endl;
  14.     }
  15.  
  16.     return 0;
  17. }
  18.  
  19. Решение с тернарен оператор:
  20.  
  21. #include <iostream>
  22.  
  23. using namespace std;
  24.  
  25. int main() {
  26.     string weather;
  27.     cin >> weather;
  28.  
  29.     cout << "It's " << (weather == "sunny" ? "warm" : "cold") << " outside!" << endl;
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement