Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > compare an input to see if it's contained within a paramter list

Reply
Thread Tools

compare an input to see if it's contained within a paramter list

 
 
Maxd out
Guest
Posts: n/a
 
      08-29-2003
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?

Tks


 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      08-29-2003

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";

return 0;
}

Did you mean something else?

-Mike



 
Reply With Quote
 
 
 
 
Kevin Goodsell
Guest
Posts: n/a
 
      08-29-2003
Maxd out wrote:

> 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.


Uh... I guess you could do this:

void func(int a, int b, int c, int d)
{
std::cout << "enter an integer: ";
int i;
std::cin >> i;

if (i == a || i == b || i == c || i == d)
{
std::cout << "That number is in the parameter list" << std::endl;
}
else
{
std::cout << "That number is not in the parameter list" << std::endl;
}
}

But somehow I don't think that's what you mean. Are you sure "Parameter
list" is the term you wanted to use?

> If so
> how can it be done and can it be done by referencing?


What is "referencing"?

Your question is very unclear.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

 
Reply With Quote
 
Chris \( Val \)
Guest
Posts: n/a
 
      08-30-2003

"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



 
Reply With Quote
 
Kevin Goodsell
Guest
Posts: n/a
 
      08-30-2003
Chris ( Val ) wrote:
> "Mike Wahler" <> wrote in message
> news:LtK3b.363$ .net...
> |
> |
> | #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";


I don't believe there is an operator<<(ostream, ostream) available, so
your code will not compile. Even if it did it wouldn't give the right
output. The original code was fine.

>
>
> 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.


You are right on this point. But I think the warnings should be errors.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass Paramter from Repeater - Can't Figure This Out Ranginald ASP .Net 2 05-03-2006 10:58 PM
SQL Output Paramter problem Islamegy® ASP .Net 1 04-16-2006 07:55 PM
Reuse paramter list and reuse connection tshad ASP .Net 5 05-17-2005 12:33 AM
Grabbing paramter in the URL Randy ASP .Net 3 02-08-2005 03:03 PM
regex for url paramter Andreas Volz Python 0 12-07-2004 10:27 PM



Advertisments