// example6.cc
// CMSC15100-2
// Winter 2005
// Define a function that does absolute value
// ternary operator

#include <iostream>

using namespace std;

// function prototypes
// returntype name(types_of_parameters) semicolon
int absolute_value_ternary(int);
int absolute_value_if(int);

int main()
{
  int a = -2;

  cout << absolute_value_ternary(a) << endl;
  cout << absolute_value_if(a) << endl;

  return 0;
}

// if b is greater than zero, the value is b
// else it's (-b)
int absolute_value_ternary( int b ) {
  return (b > 0) ? b : (-b);
}

int absolute_value_if( int b ) {
  if (b > 0) {
    return b;
  }
  else {
    return -b;
  }
}
