C++ Code: Check Temperature and Output Weather Condition
You can use conditional statements to determine if the temperature is greater than or less than 50 and write the appropriate text. Here is an example code:
#include <iostream>
using namespace std;
int main() {
int temperature;
cout << 'Enter the temperature: ';
cin >> temperature;
if (temperature == 50) {
cout << 'Moderate weather' << endl;
}
else if (temperature > 50) {
cout << 'Hot weather' << endl;
}
else {
cout << 'Cold weather' << endl;
}
return 0;
}
In this example, the user is asked to enter the temperature, and then the conditional statement is used to write the appropriate text based on the value of the entered temperature.
原文地址: http://www.cveoy.top/t/topic/c05Y 著作权归作者所有。请勿转载和采集!