Write the definition of a function printLarger , which has two int parameters and returns nothing. The function prints the larger value of the two parameters to standard output on a single line by itself.

this is what i have so far:

void printLarger(int, int){

}

I have to write something between the curly braces but I don't know what, please help me. thanks

Recommended Answers

All 2 Replies

if a is larger than b return a, else return b

void printLarger(int a , int b)
{
if (a < b)
return a;
else
return b; 
}

p.s i get mixed up with the < and > operators cant remember which one means which

P.S do you think you could put all your questios in 1 post next time?

>>which has two int parameters and returns nothing
>if a is larger than b return a, else return b
Um, no. If a is larger than b you print a, otherwise print b.

>p.s i get mixed up with the < and > operators cant remember which one means which
This is grade school mathematics, < means less than and > means greater than. Didn't anyone ever teach you the alligator rule? The alligator always wants to eat the biggest number:

a < b // b is bigger than a, eat b
a > b // a is bigger than b, eat a

void printLarger ( int a , int b )
{
  if ( a > b )
    cout<< a <<endl;
  else
    cout<< b <<endl;
}

Alternatively:

void printLarger ( int a , int b )
{
  if ( a < b )
    cout<< b <<endl;
  else
    cout<< a <<endl;
}
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.