#include <iostream>
#include <iomanip>

using namespace std;

int c0=0,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c9=0;

class array{
      private:
              int arr[10];
      public:
             
             friend istream& operator >> (istream& in, array& a)
             {    
                 cout<<"Enter 10 value in the array!\n\n";
                 
                 for (int i=0; i<10; i++)
                 {
                     cout<<"Enter the value at ["<<i<<"]: ";
                     in>>a.arr[i];
                 }   
             }
             
             void check_count (void)
             {    
                  int rem=0;
                  
                  for (int i=0; i<10; i++)
                  {
                      if (arr[i] == 0 ){c0++;}
                      
                      while (arr[i]>0)
                      {
                            rem = arr[i] % 10;
                            
                            arr[i] = arr[i] / 10;
                            rem -= arr[i];
                      }
                      
                  if (rem == 1){c1++;}
                  if (rem == 2){c2++;}
                  if (rem == 3){c3++;}
                  if (rem == 4){c4++;}
                  if (rem == 5){c5++;}
                  if (rem == 6){c6++;}
                  if (rem == 7){c7++;}
                  if (rem == 8){c8++;}
                  if (rem == 9){c9++;}
                  
                  }
             }
             
             void display (void)
             {
                  cout<<"\nNo. of 0's: "<<c0;
                  cout<<"\nNo. of 1's: "<<c1;
                  cout<<"\nNo. of 2's: "<<c2;
                  cout<<"\nNo. of 3's: "<<c3;
                  cout<<"\nNo. of 4's: "<<c4;
                  cout<<"\nNo. of 5's: "<<c5;
                  cout<<"\nNo. of 6's: "<<c6;
                  cout<<"\nNo. of 7's: "<<c7;
                  cout<<"\nNo. of 8's: "<<c8;
                  cout<<"\nNo. of 9's: "<<c9;
             }
};

int main ()
{
    array a1;
    
    cin>>a1;
    
    a1.check_count ();
    
    a1.display ();
    
    cout<<endl<<endl;
    
    system ("pause");
    return (0);
}

The problem is that my program is not counting the zero if the number is as follows "01" or "001" & so on... Plus if the number contains only zeros for eg "00" or "000" the the variable for counting zeros should increase. But in the end my program is not doing the desired task :-( Please help me out as soon as possible...

Recommended Answers

All 2 Replies

That's because the system stores the number as 1... 0001 and 1 are equivalent so if you need leading zeros, try storing the value as a string.

Thank you programming gurus :-)

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.