title: How to make counter that counts zeros?
body: <p>I have 4 elements, let's say p1, p2, p3, p4. They all can have value 0 or anything but 0. (low and high). I need counter that equals 4. When any of those elements is high counter should do -1.
  For example the user enters following values: p1=0, p2=1, p3=1, p4=0. Final value should be 2.
  So I tried it with array of 4 elements, and one counter that decreases value every time one element is not 0 (It's high).
  This code only works when i have all 0 or all high. What can i change?</p>
  <pre><code>int main()
  {
      int array[4]={0,0,0,0};
      
      printf(&quot;Enter value p1:&quot;);
      scanf(&quot;%d&quot;, &amp;array[0]);
      
      printf(&quot;Enter value p2:&quot;);
      scanf(&quot;%d&quot;, &amp;array[1]);
      
      printf(&quot;Enter value p3:&quot;);
      scanf(&quot;%d&quot;, &amp;array[2]);
      
      printf(&quot;Enter value p4:&quot;);
      scanf(&quot;%d&quot;, &amp;array[3]);
      
      int i=4;
      int j=0;
      if (array[0]!=0)
      {
        j++;
          
          if(array[1]!=0)
              {
                  j++;
              
              if (array[2]!=0)
              {
                  j++;
                  
                  if (array[3]!=0)
                  {
                      j++;
                  }
              }
              } }
      int z=i-j;
      
      printf(&quot;%d&quot;, z);
  </code></pre>