c - I can not get the loop to cycle 20 times and ask for a number between 1 and 6. Can anyone see what I have coded wrong? -


i trying ask 20 integers , count when number 2 , 5 selected static variable. can using code blocks. not asking 20 number 1.

#include <stdio.h> #include <stdlib.h>  int totalcount2(int ); \*this added function call*\ int totalcount5(int ); void output( int, int); int main() { int count2; int count5; int yournumber; int yournumbercounter;  yournumbercounter = 1; count2 =0; count5 =0;      printf("please enter number between 1 , 6.\n");     scanf("%d", &yournumber);  while(yournumbercounter<= 20)     {        if(yournumber ==2){         totalcount2(count2);         break;         }         else if(yournumber ==5){             totalcount5(count5);             break;         }         else if(yournumber <= 6 || yournumber >=1){             yournumbercounter = yournumbercounter +1;         }         else if(yournumber >6 || yournumber <6){             printf("you have choose number between 1 , 6. try again");         }      }  return 0; }      int totalcount2(int count2){         static int count2only;         count2only = count2++;         return count2only;     }     int totalcount5(int count5){         static int count5only;         count5only += count5;         return count5only;     }     void output(count2, count5){     printf("out of 20 numbers input. entered number 2 %d times\n entered number 5 %d times\n", count2, count5);     return; } 

i not sure if using static variables count2 , count5 correctly. studying book , think maybe sees doing wrong.

printf("please enter number between 1 , 6.\n"); scanf("%d", &yournumber); while(yournumbercounter<= 20) 

is outside of loop

should be

while(yournumbercounter<= 20){ printf("please enter number between 1 , 6.\n"); scanf("%d", &yournumber); 

the break statement terminates execution of nearest enclosing do, for, switch, or while statement in appears. control passes statement follows terminated statement.

delete breaks.

also learn use debugger.

google: "how debug c code" , name of ide - program write code with.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -