/*******************************************************/
//R.A. Hillayrd
//fun1.cpp
//Last Modified 10/08/2001
//program to use demonstrate basics of user defined functions
/*******************************************************/

#include<iostream>
#include<cctype>     //for toupper

using namespace std;

//function prototypes
char printMenu();                   //print menu of choices - return choice
int min(int a, int b);              //return the smallest of two integers
void printChar(char ch, int num);   //print a line of n characters

int main()
  {
  char choice, ch;  //char variables for user input
  bool flag = true; //flag to control loop
  int a,b;          //integer variables for user input

  while(flag)
    {
    choice = printMenu();   //print menu

    switch(choice)   //do user request
      {
      case 'S' : cout << "Enter two integers: ";
                 cin >> a >> b;
                 cout << "The Smallest of " << a << " and " << b
                      <<  " is " << min(a,b) <<endl;
                 break;
                 
      case 'P' : cout << "Enter a character and number of times: ";
                 cin >> ch >> a;
                 printChar(ch,a);
                 break;  

      case 'Q' : cout << "bye for now\n";
                 flag = false;
                 break;

      default  : cout << choice << " is undefined\n";
      }//end switch
    }//end while flag
   return 0;
  }//end main
/***********************************************************/
char printMenu()
  {
  char choice;
  do
    {
    cout << "\nWelcome to the function demo program\n";
    cout << "------------------------------------\n";
    cout << "Choose one of the following\n";
    cout << "  S  find the smallest of two integers\n";
    cout << "  P  print a line of characters\n";
    cout << "  Q  To quit\n\n";
    cout << "Enter your choice: "; 
    cin >> choice;
    choice = toupper(choice);
    }while(choice != 'S' && choice != 'P' && choice != 'Q');
  return choice; 
  }
/***********************************************************/
//return the smallest of two integers
/***********************************************************/
int min(int var1, int var2)
  {
  if(var1 <= var2)
    return var1;
  return var2;
  }
/***********************************************************/
//prints a line of characters
/***********************************************************/
void printChar(char ch, int num)
  {
  for(int j = 0; j < num; j++)
    {
    cout << ch << " ";
    }
  cout << endl;
  }
/***********************************************************/
/*********************Program Output************************

Welcome to the function demo program
------------------------------------
Choose one of the following
  S  find the smallest of two integers
  P  print a line of characters
  Q  To quit

Enter your choice: s
Enter two integers: 77 3
The Smallest of 77 and 3 is 3

Welcome to the function demo program
------------------------------------
Choose one of the following
  S  find the smallest of two integers
  P  print a line of characters
  Q  To quit

Enter your choice: S
Enter two integers: -8 88
The Smallest of -8 and 88 is -8

Welcome to the function demo program
------------------------------------
Choose one of the following
  S  find the smallest of two integers
  P  print a line of characters
  Q  To quit

Enter your choice: s
Enter two integers: 4 4
The Smallest of 4 and 4 is 4

Welcome to the function demo program
------------------------------------
Choose one of the following
  S  find the smallest of two integers
  P  print a line of characters
  Q  To quit

Enter your choice: P
Enter a character and number of times: X 23
X X X X X X X X X X X X X X X X X X X X X X X

Welcome to the function demo program
------------------------------------
Choose one of the following
  S  find the smallest of two integers
  P  print a line of characters
  Q  To quit

Enter your choice: P
Enter a character and number of times: O 24
O O O O O O O O O O O O O O O O O O O O O O O O

Welcome to the function demo program
------------------------------------
Choose one of the following
  S  find the smallest of two integers
  P  print a line of characters
  Q  To quit

Enter your choice: q
bye for now

*/