"Mike Wahler" <> wrote in message
news:LtK3b.363$ .net...
|
| Maxd out <> wrote in message
| news:u3K3b.71320$...
| > Hi all
| >
| > As a newbie to C++ just wondering if you can compare a user input e.g. the
| > integer 2 to see if that integer is contained within a parameter list. If
| so
| > how can it be done and can it be done by referencing?
|
|
| #include <iostream>
|
| bool contained(int& param1, int& param2, int& param3)
| {
| int input(0);
| return (std::cin >> input) && (input == param1 ||
| input == param2 ||
| input == param3);
| }
|
| int main()
| {
| std::cout << "User input is"
| << contained(1, 2, 3) ? " " : " not "
| << "contained in parameter list\n";
std::cout << "User input is "
<< contained( 1, 2, 3 ) ? std::cout << " " :
std::cout << " not contained in parameter list\n";
Hello Mike, you left a couple of important bits out

.
Btw, why not pass by const reference, or by value ?
It saves the warnings about temporaries.
Cheers.
Chris Val