How do I go about writing a user-defined function named Get_Inputs that when called, the function will prompt for three integers and send these numbers to its calling environment.

What do you know about functions? If you want to return 3 variables you'll probably need an array of ints. Or you could pass 3 ints by reference.

can you give me an example of it?

is this right anybody, please i need a solution

Get_inputs ( int &a, int &b, int&c)

{

cout <<"Enter three integers "<<endl;

cin << a,b,c;

system ("PAUSE");

return 0;

}

Get_inputs (x,y,z)

Good start. You got the reference arguments right.

First, function needs a return type in its definition, even if it returns nothing. Place the keyword "void" in front of the function name.

Your input statement is wrong on two counts. You have the arrows pointing wrong way (think of them as pointing in the direction of information flow - from cin to the variables.) Also, when doing a multiple input statement, you must use separate arrows for each variable destination.

Do not return 0 from a (now) void function. In fact, void functions do not require a return statement at all.

Do not put a pause in the function (no output other than your prompt belongs there.)

void Get_inputs ( int &a, int &b, int&c)
{
    cout << "Enter three integers " << endl;
    cin >> a >> b >> c;
}

is this right anybody, please i need a solution

Get_inputs ( int &a, int &b, int&c)

{

cout <<"Enter three integers "<<endl;

cin << a,b,c;

system ("PAUSE");

return 0;

}

Get_inputs (x,y,z)

It's right in some ways, wrong in others. It's right in that you have a decent parameter list:

( int &a, int &b, int&c)

It's wrong because you don't say what the function returns. You have it returning 0 but do not declare that the function returns an integer:

Get_inputs ( int &a, int &b, int&c)

I'd go on but I just hit "Preview" and vmanes beat me to it so I'll end here.

thanks fellas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.