0

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

3
Contributors
2
Replies
6
Views
12 Years
Discussion Span
Last Post by Narue
0

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?

0

>>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;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.