Thread: Why counter won't reset in my C program?

  1. #1
    Registered User
    Join Date
    May 2018
    Posts
    8

    Why counter won't reset in my C program?

    Every time when the if condition is true the value of count should be printed then become zero. but that's not happening, why?
    OUTPUT:
    j=99 count=3
    j=104 count=104
    j=98 count=98. Why the values of j and count are same?


    Code:
    int main()
    {
         int j, count=0,p=0, asc[10]={ 99, 104, 98};
         for(j=97; j<=122; j++)
         {
            count++;    
             if(asc[p]==j)
             {
                 
                 printf("J=%d\n\n",j);
                 printf("count=%d\n\n",count);
                     count=0;
                 p++;
                 j=0;
                 
             }
            
         }
    return 0;
    }
    Last edited by sunil9211; 6 Days Ago at 09:10 AM. Reason: improvement

  2. #2
    Registered User
    Join Date
    May 2018
    Posts
    8
    Solved! I made a silly mistake. i should have set the value of j as 97 not zero.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-24-2017, 07:13 PM
  2. Replies: 3
    Last Post: 04-20-2014, 12:14 PM
  3. Using If commands to reset program
    By Kevineze in forum C++ Programming
    Replies: 28
    Last Post: 11-23-2006, 07:38 AM
  4. Trying to loop my program or reset it Dev c++
    By GameGenie in forum C++ Programming
    Replies: 8
    Last Post: 07-21-2005, 12:39 PM
  5. Replies: 2
    Last Post: 10-23-2004, 03:46 AM

Tags for this Thread