Lab (6)
More about Functions

The goal is to:
    Learn about different types of functions
    Learn to write a more complex code with multiple function calls
=================================================
Preparation:  Create the lab6 diretory and complete your work there.

In this lab, you are required to write a C++ program called temp.C during the lab hour.  The program will convert:
    Choice (1): a temperature in Celsius to Fahrenheit
    Choice (2): a temperature in Fahrenheit to Celsius
    Choice (others) : Error, I do not know what you want to do.

Your code will ask users to input 'y' or 'Y' to compute a new case.  The program terminates if the user enters anything else besides 'y' or 'Y'.

Here is a template that you can use for your loop:

int main()
{
    char ans = 'y';
    ....
    ....

    while( ans == 'y' || ans == 'Y')
    {
         ....
         ....
         ....

         cout << "Do you wish to compute a new case \n";
         ans = Answer( );

     }
     ....
}

I have given you the following functions.  You are required to use all these functions in your code.

void Description( )
{
      cout << "This program will convert temperatures in Celsius to Fahrenheit or \n";
      cout << "Fahrenheit to Celsius based on the choice that the user makes \n";
      cout << "Choices are:  \n";
      cout << "Choice (1): a temperature in Celsius to Fahrenheit \n";
      cout << "Choice (2): a temperature in Fahrenheit to Celsius \n";
      cout << "Choice (others) : Error, I do not know what you want to do. \n";

     cout << "The program keeps converting new cases for as long as the user \n";
     cout << "answers y or Y to a question that is asked after completion of each case \n";
}

char Answer()
{
 //This function asks users to input a character and will return that character
// to the calling function (in your case the calling function is main)

     char answer;
     cout << "Do you wish to compute a new case \n";
     cout << "Answer Y or y to continue, anything else to terminate. \n";
     cin >> answer;
     cout << "\n";
     return answer;
}

void Option(int& choice)
{
//This function will ask users to input a choice for the case that they wish to compute

     cout << "Please enter \n";
     cout << " (1) if you wish to convert a temperature in Celsius to Fahrenheit \n";
     cout << " (2) if you wish to convert a temperature in Fahrenheit to Celsius \n";
     cout << " Anything else will be invalid \n";

     cout << "Enter your choice : "
     cin >> choice;
     cout << "\n";
}

double Far_to_Cel(double tf)
{
//This function will convert a temperature in Fahrenheit to Celsius.
//It returns the converted value via return.
    double tc;
    tc = (5.0/9.0)*(tf - 32);
    return tc;
}

void Cel_to_Far(double tc, double& tf)
//This function will convert a temperature in Celsius to Fahrenheit.
//The converted value, tf, will be updated via Call_by_reference.
{
    tf = (9.0/5.0)*(tc) + 32;
}
 
That is all.  Now you need to put the pieces together. Once you are done with your code submit it to lab6 directory.
~rt/bin/submit1440_103  lab6  temp.C

Answer these questions:
What is the difference between the way the value of the converted temperature has been sent to the main in the two functions Cel_to_Fah and Fah_to_Cel?
 

In Cel_to_Far function, explain why did we only use & for tf?
 

In Cel_to_Far function, could we use & with tc?