CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2012
    Posts
    8

    [RESOLVED] Help writing code.

    value Write a function, contains, that accepts an array of integers, the number of elements in the array and an integer value, and returns a boolean value indicating whether the value appears as an element of the array (arrays as parameters, basic search algorithm)

    bool contains(int a[], int n, int val)
    {
    for(int i = 0; i < n; i++)
    {
    if(a[i] == val)
    {
    return = true;
    }
    }
    }

    what am i doing wrong..

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: [RESOLVED] Help writing code.

    Quote Originally Posted by mejiac3 View Post

    what am i doing wrong..
    Code:
    return = true;
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: [RESOLVED] Help writing code.

    You also miss a return false; at the end of the function but your compiler has probably already told you that.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured