Greetings:

I am having some errors on this code:
Any ideas what is missing in the code?
Thanks,

Dani

`

     #include<stdio.h>
     void func_count(int);

     int main( )
    {
            int i, num;

           for(i = 1; i < 21; i ++ )
           {
                 scanf(“%d”, &num);
                 if(num < 1 || num > 6)
                       printf(“Error: Invalid number %d\n”);
                 else
               func_count(num);
           }
           func_count(0);
           return 0;
     }


      func_count(int n)                          /* count occurrances of n */
     {
             static int count2, count5;
     count2 += ( n == 2);
     count5 += ( n == 5);
      if( n== 0)
     {
                    printf(“There are %d occurances of 2\n”, cnt_2);
                    printf(“There are %d occurances of 5\n”, cnt_5);
              }

               return;
      }

`

Your main problems appear to be in func_count. you didn't declare the return type, which in this case should be void, since that is how your prototype has it declared. Also,the 2 variables you have in that function are count2 and count5, however your printf statement is trying to print cnt_2 and cnt_5 which aren't declared anywhere.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.