-2
I need this code generates the value 0 or 1, can anyone help? And if it is 1 need q write it rained and 0 did not rain
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
{
int i;
float chuva;
srand( (unsigned)time(NULL) );
for(i=0 ; i<=1 ; i++)
{
printf("chuva %d = %.0f%\n",i, rand());
if(chuva=1)
printf("Choveu\n");
else
printf("Nao choveu\n");
Could you describe in your words what the function
rand
returns?– Woss
Please edit the question to limit it to a specific problem with sufficient detail to identify an appropriate answer.
–
I don’t know if it’s right. I tried to do so tbm #include <stdlib. h> #include <stdio. h> #include <time. h> float rain() { int i; float rain; for(i=0 ; i <= 1 ; i++) { rain = ( 0 + Rand()%1); printf("rain= %d: %d n",i, Rand()); if(rain=1) printf("Rained n"); Else printf("Rained n"); }}
– Uzzoper Fortnite
I think you want to change the line
if(chuva=1)
forif(chuva==1)
.– Krossbow
0 + rand() % 1
, can explain what you did here?– Woss
I’m still a beginner in language, something I did might be wrong
– Uzzoper Fortnite
Fine, but being a beginner doesn’t justify writing code you can’t justify. Otherwise you will be writing code randomly and with lots of luck at some point will produce the expected result. How about taking advantage that it is still in the beginning, take a step back and try to understand the code you wrote?
– Woss