int main(void) { / Initialize variables and function prototype/ unsigned int seed; int heads = 0, tails = 0, tosses, k, x;
/* Get user inputs */ printf("Enter the number of tosses: \n"); scanf("%lf",&tosses); printf("Enter a positive integer seed value: \n"); scanf("%u",&seed); srand(seed); /* Generate a certain number of tosses. */ for (k=1;k<=tosses;k++) x = rand()%2; if x = 1 heads++; else tails++; /* Print Outputs to screen */ printf("Number of Heads: %f and Number of tails: %f", heads, tails; system ("PAUSE"); /* Exit Program */ return 0;
} /-------------------------------------------------------------------------/
????????????????????????????????????????????
This syntax:
if x = 1
Is wrong on several levels, it is missing () around the condition, and it is using the wrong symbol
=
does assignments
==
does comparisons
it probably should look like
if (x == 1)
perhaps. There are other code errors. I think you are missing some
{}
ALSO,
printf("Number of Heads: %f and Number of tails: %f", heads, tails;
See anything missing here? Hint )
Your code doesn't compile because it has errors. Logical and syntactical.
Wayne
Log in to post a comment.
include <stdio.h>
include <stdlib.h>
int main(void)
{
/ Initialize variables and function prototype/
unsigned int seed;
int heads = 0, tails = 0, tosses, k, x;
}
/-------------------------------------------------------------------------/
????????????????????????????????????????????
This syntax:
if x = 1
Is wrong on several levels, it is missing () around the condition, and it is using the wrong symbol
=
does assignments
==
does comparisons
it probably should look like
if (x == 1)
perhaps. There are other code errors. I think you are missing some
{}
ALSO,
printf("Number of Heads: %f and Number of tails: %f", heads, tails;
See anything missing here? Hint )
Your code doesn't compile because it has errors. Logical and syntactical.
Wayne