Menu

HeadsorTails.This won't compile.. How come?

2009-03-06
2012-09-26
  • Andrew Charbonneau

    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;

    /* Get user inputs */
    printf(&quot;Enter the number of tosses: \n&quot;);
    scanf(&quot;%lf&quot;,&amp;tosses);
    printf(&quot;Enter a positive integer seed value: \n&quot;);
    scanf(&quot;%u&quot;,&amp;seed);
    srand(seed);
    
    /* Generate a certain number of tosses. */
    for (k=1;k&lt;=tosses;k++)
      x = rand()%2;
      if x = 1
        heads++;
      else
        tails++;
    
    /* Print Outputs to screen */
    printf(&quot;Number of Heads: %f and Number of tails: %f&quot;, heads, tails;
    
    system (&quot;PAUSE&quot;);
    /* Exit Program */
    return 0;
    

    }
    /-------------------------------------------------------------------------/

    ????????????????????????????????????????????

     
    • Wayne Keen

      Wayne Keen - 2009-03-06

      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.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.