Thread: Outputting numbers in arrays

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    30
    So would it be something like this?

    Code:
    int numbers (int draw[], int entry[])
    {
         for(int i=0; i<MAXSIZE; i++)
        {
            for(int j=0; j<MAXSIZE; j++)
            {
                if(draw[i]==entry[j])
                
                break;
                
            }
            printf; draw[i];
        }
        
    }

    Sorry if that is totally wrong we just havn't learnt about how to use print!

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by rachael033 View Post
    So would it be something like this?

    Code:
    int numbers (int draw[], int entry[])
    {
         for(int i=0; i<MAXSIZE; i++)
        {
            for(int j=0; j<MAXSIZE; j++)
            {
                if(draw[i]==entry[j])
                
                break;
                
            }
            printf; draw[i];
        }
        
    }

    Sorry if that is totally wrong we just havn't learnt about how to use print!
    Forget printf(). Use std::cout, as I said. If you see that draw[i] and entry[i] are equal, then you can print them right then and there like this:

    Code:
    std::cout << "Matching element = " << draw[i] << std::endl;

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    30
    Ok thanks it seems to be kind of working but I am getting the right numbers printed out but then a big random number at the end.
    I input 1 2 3 4 5 6 in both arrays so that should be the output but instead of...
    1 2 3 4 5 6
    i get
    1 2 3 4 5 6 2293468

    Here is the function...

    Code:
    int numbers (int draw[], int entry[])
    {
        
        for(int i=0; i<MAXSIZE; i++)
        {
            for(int j=0; j<MAXSIZE; j++)
            {
                if(draw[i]==entry[j])
                cout << draw[i] << " ";
            }
    
        }
        
    }
    I output it like this..

    Code:
    cout << numbers(draw, entry) << endl;
    Any reason why the extra number is showing up?
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about random numbers
    By Kempelen in forum C Programming
    Replies: 2
    Last Post: 07-02-2008, 06:28 AM
  2. Help with Rational Numbers (C++)
    By cloudjc in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2008, 04:03 PM
  3. Replies: 4
    Last Post: 04-19-2005, 08:05 PM
  4. Doing multiplication using numbers in arrays
    By neandrake in forum C++ Programming
    Replies: 17
    Last Post: 11-05-2004, 11:07 AM
  5. using arrays to sort numbers
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:14 PM