满意答案
hrt445310
2018.10.18
#include
#include
#include
int main()
{
int temperature; //温度
int weather; //天气
char str_weather[5];
int wind; //风
srand((unsigned)time(0));//初始化随机种子
temperature=rand()%63-20; //获取-20到42的随机数
while(1)
{
weather=rand()%3;//获取天气情况:0为雨,1为雪,2为晴
if(temperature<0 && weather==0) //如果温度小于0度并且天气为雨,则重新获取
{
continue;
}
switch(weather)
{
case 0:
strcpy(str_weather,"雨");
break;
case 1:
strcpy(str_weather,"雪");
break;
case 2:
strcpy(str_weather,"晴");
break;
}
break; //如果符合规则,则退出循环
}
wind=rand()%13;//获取风级:0-12
printf("今天温度:%d 天气:%s 风级:%d级\n",temperature,str_weather,wind);
return 0;
}
00分享举报