Thread: problem with a c++ program

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    1

    Unhappy problem with a c++ program

    Hello! I have a problem with a c++ program. It's about to find the unique values in an array and to copy the in another array and also to count how many times each value is met in the first array. I would be very appreciated if you help me
    Code:
    #include<iostream>
    using namespace std;
    void main()
    {
      int a[5];
      int b[5];
      int p;
      int i;
      for (p=0; p<5; p++){
         cout<<"Enter the numbers ";
         cin>>a[p];
      }
      int flag=1;
      int temp;
      int j;
      for(i = 0; (i <5) && flag; i++)
         {
              flag = 0;
              for (j=0; j < 4; j++)
             {
                   if (a[j+1] < a[j]) 
    	  { 
                        temp = a[j];             
                        a[j] = a[j+1];
                        a[j+1] = temp;
                        flag = 1;
    			   }
          }
      }
      int br=0;
      for(p=1;p<5;p++)
      {
    	  if(a[p]==a[p-1])
    	  {
    		  br++;
    	  }
      }
       
      b[0]=a[0];
      int d,m=1;
      for(d=1;d<5;d++)
      {
    	  if(a[d]!=a[d-1])
    	  {
    		  b[m]=a[d];
    		  m++;
    	  }
      }
      
    	  
      cout<<"The numbers are"<<b[0];
      for(i=1;i<m;i++)
    	  cout<<b[i];
      cout<<"The number is: "<<br;
    
    
    }
    My problem is how to count how many times each value is met.
    Last edited by bianca21; 03-29-2009 at 12:13 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    How would you do it? Say you were in Vegas playing blackjack and you wanted to know how many aces had gone by in the current deck. How would you do so?

    You need to do the same thing here; the catch is you need to know what the possible values the original array could have, so you know what you're looking for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi Thread Program Problem
    By ZNez in forum C Programming
    Replies: 1
    Last Post: 01-03-2009, 11:10 AM
  2. Program Termination Problem
    By dacbo in forum C Programming
    Replies: 3
    Last Post: 01-23-2006, 02:34 AM
  3. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 02:38 PM
  4. Replies: 20
    Last Post: 06-12-2005, 11:53 PM