what is wrong with dis code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nikhil143garg
    New Member
    • Mar 2007
    • 1

    what is wrong with dis code

    Input a list if integers, just like last time, then input a second list. Put the first list in array a, the second in array b. Let counta be the number of integers in a, and countb the number of integers in b. Your task is to print all numbers that occur in both lists. Like last time, you must loop over array a, and decide whether to print a[i] or not. If a[i] occurs in array b, from b[0] to b[countb-1] inclusive, then print a[i]; otherwise not.

    Code:
    #include <iostream>
     
    using namespace std;
      int a[30]
       
      int b[3]
       
      int counta, countb, n;
       
      int k,j; 
       
     int main ()
    
    {
      
      int  used_number;
      
      cout<<"Enter the first list of numbers\n";
      
      cin>> k;  
    
       
      for (k=0; k>=20; k++)
        
       {
          
         cin>> a[k];
          
         if a[k]==0
           
         return k;
       
       }
    
      
     for  (k=0; used_number=k+1)
      
        {
         
          for (j=(k+1); J=used_number+1; j++
          
           {
            
              if a[k]==a[j]
            
              a[j]=[-2]
          
           }
      
        }
    
    
         
      for (k=0; k= used_number+1;k++)
           
        {
             
          if a[k]==[-2]
            
          cout<< a[k];
          
        }
    
      
     bool find (int a[k], int size, target)
         
       {
           
         int k;
           
        for(k=0; k<size;k++ )
             
         {
              
          if (a[k]==target)
                 
          return true
            
         }
           
       return false
        
       }
    
    
        
       for (k=0;k<countb; k++)
          
      {
             
        found= find (a, counta, b[k]);
              
       if (found)
               
       cout<< b[k]<< "0";
       
      }
      
      return 0;
    
    }
    Last edited by Ganon11; Mar 26 '07, 06:44 PM. Reason: code tags added
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

    We have no idea what is wrong with it. Is it not compiling correctly? Is there an error message, or is the output incorrect? You need to ask a pointed question about a specifc part of your code.

    Comment

    • bluesteel
      New Member
      • Mar 2007
      • 84

      #3
      The syntax in "for" is terribly bad constructed and you lack ";" in some parts

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #4
        And:

        1. You are missing input of second list;

        2.You have not properly declared some of local variables;

        You have declared like:
        Code:
           int a[30]
           
          int b[3]
        instead of:

        Code:
          int a[30];
           
          int b[3];

        3.You forgot to close some of bracets.

        Code:
        for (j=(k+1); J=used_number+1; j++
        instead of:

        Code:
        for (j=(k+1); J=used_number+1; j++)

        Savage

        Comment

        Working...