Traditional Culture Encyclopedia - Weather inquiry - C language programming

C language programming

#include?

#include?

#include??

int?main()

{

int?temperature;?//temperature

int?weather;?//weather

char?str_weather[5];

int?wind;?//Wind

srand((unsigned)time(0));//Initialize random seed?< /p>

temperature=rand()%63-20;?//Get a random number from -20 to 42?

while(1)

{

weather=rand()%3;//Get the weather conditions: 0 is rain, 1 is snow, 2 is sunny

if(temperature<0?&&?weather==0)? //If the temperature is less than 0 degrees and the weather is rainy, reacquire

{

continue;

}

switch(weather )

{

case?0:

strcpy(str_weather,"Rain");

break;

< p> case?1:

strcpy(str_weather,"snow");

break;

case?2:

strcpy (str_weather,"Qing");

break;

}

break;?//If the rules are met, exit the loop?

< p> }

wind=rand()%13;//Get wind level: 0-12?

printf("Today's temperature: %d? Weather: %s? Wind Level: %d level\n",temperature,str_weather,wind);

return?0;

}