Heblany Heblany - 1 year ago 39
C Question

if statement with double value in c language?

I am beginner to c language and I am practicing it to developed my code of my study. I am trying to build a

.c
function with
if
statement. I need the function to do some work if the condition is true and return other value of if not. I am come from R. I am reading many tutorial about
.c
and could not find some help for this issue. Any help please?

Note: What I try to do is to generate uniform numbers and then conditions based on the values of these numbers.

#include <stdio.h>
int main()
{
double 0.5 ;
double *w;
for (i=0;i<= int 10; i++) w[i] = runif(0,1);
if (w[i] < double 0.5 )
{
int 4 + int 5
} else if w[i] < double 0.2){
int 10 + int 5
}else{
w[i]
}
return 0;
}


I tried this but I got this errors:

expected identifier or '{'
use of undeclared identifier 'w'

Answer Source

I think that none of us can deduce from your code what you want to do exactly, however, here is a version that compiles and is correct. Now you adapt it to let it do what you actually want to do.

#include <stdio.h>
int main()
{
   double w[11];
   int i, j;
   for (i = 0; i <= 10; i++) {
      w[i] = runif(0,1);
      if (w[i] < 0.5 ) {
         j= 4 + 5;
      } else if (w[i] < 0.2) {
         j= 10 + 5 ;
      }else {
         printf ("w[%d]= %f",i, w[i]);
      }
   }
   return 0;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download