If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

New to c++ and getting an error for searching an Array

I am getting an error and I can't figure out what I am doing wrong. I have compared to similar code in the text book and I am still over looking something any help with what I am missing would be appreciated!

// ***************************************************
// The searchList function performs a linear search on the int array
// luckyNumbers. If the number is with in luckyNumbers it will return
// message confirming the numbers are winners otherwise it it will
// notify user that the numbers are not winning numbers
// ***************************************************

Re: New to c++ and getting an error for searching an Array

To correctly use code tags with c/c++ code rather than use PHP tags, Go Advanced, select the code and click '#'.

All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

Re: New to c++ and getting an error for searching an Array

Your searchList() declaration has the const int [] as the first argument - but for the definiton it is int [].

As the contents of the array luckyNumbers are not intended to be changed, it would be better to define the array as const.

To output a new line within a string literal you use \n and not /n.

Also, it would be considered a better design to split the operations of obtaining a number and searching for it into separate functions rather than having both these operations within the same function. The search function could then take as an argument the number to find and return a bool true or false which the calling function (or a message function) could then use to determine which message to display. Your search function is then more general which could be reused.

All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!