I need this code to generate the value 0 or 1, (not all the code is there)

Asked

Viewed 34 times

-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?

  • 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"); }}

  • I think you want to change the line if(chuva=1) for if(chuva==1).

  • 1

    0 + rand() % 1, can explain what you did here?

  • I’m still a beginner in language, something I did might be wrong

  • 1

    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?

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.