Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function that receives four integers..

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Hey everyone!
Does anyone know the C++ code for a function that receives four integers?
 
Can you give more precision ?
Did you meant that you want to create a function that will receive four parameters or something else ?

prototype for a fuction with four integer parameters:

void Somefunction( int x1, int x2, int x3 )
 
I'm suppose to write out a function that the user will input 4 integers and the function should calculate the average of the four integers.

I'm a beginner at this so please help..
 

int avg(int a,int b, int c, int d)
{
return sum of a-d divided by 4
}

int main()
{
int a,b,c,d;
cout<<&quot;Enter 4 values: &quot;;
cin>>a>>b>>c>>d;
cout<<&quot;The average is: &quot;<<avg(a,b,c,d)<<endl;

return 0;
}

That is the gist of it

matt
 
does anyone know what you'd do to read in these four integers and then have the program tell you whether the four integers are in ascending order?

i'm new at this, too, and trying desperately to understand!
 
In order for the four integers to be in ascending order, integer1 <= integer2 <= integer3 <= integer4 must be true.

You can write a function returning bool true or false which tests this using a for-loop, or the hard-coded logic listed above for simplicity.

e.g.

bool ascendingCheck( int a, int b, int c, int d )
{
if ( above logic is true )
return true;
else
return false;
}

will return true if numbers are in ascending order, or false if not.
 
In order for the four integers to be in ascending order, integer1 <= integer2 <= integer3 <= integer4 must be true.

You can write a function returning bool true or false which tests this using a for-loop, or the hard-coded logic listed above for simplicity.

e.g.

bool ascendingCheck( int a, int b, int c, int d )
{
if ( above logic is true )
return true;
else
return false;
}

will return true if numbers are in ascending order, or false if not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top