Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- double degrees;
- cin >> degrees;
- string weather;
- if (degrees >= 5 && degrees < 12) {
- weather = "Cold";
- }
- else if (degrees >= 12 && degrees < 15) {
- weather = "Cool";
- }
- else if (degrees >= 15 && degrees <= 20) {
- weather = "Mild";
- }
- else if (degrees > 20 && degrees < 26) {
- weather = "Warm";
- }
- else if (degrees >= 26 && degrees <= 35) {
- weather = "Hot";
- }
- else {
- weather = "unknown";
- }
- cout << weather << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- double degrees;
- cin >> degrees;
- string weather =
- degrees >= 5 && degrees < 12 ? "Cold" :
- degrees >= 12 && degrees < 15 ? "Cool" :
- degrees >= 15 && degrees <= 20 ? "Mild" :
- degrees > 20 && degrees < 26 ? "Warm" :
- degrees >= 26 && degrees <= 35 ? "Hot" : "unknown";
- cout << weather << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement