Thursday, January 5, 2017

Programming Challenge 6.12 - Star Search

/* Star Search - A particular competition has five judges, each of whom
   awards a score between 0 and 10 to each performer. Fractional scores,
   such as 8.3, are allowed. A performer's final score is determined by
   dropping the highest and lowest score received, then, averaging the
   three remaining scores.
 
   This program uses this method to calculate a contestant's score. It
   includes the following functions:
 
   * void getJudgeData()
   * void calcScore()

   The last two functions are called by calcScore, which uses the returned
   information to determine which of the top scores to drop.

   * int findLowest()
   * int findHighest()

   Input Validation: No judge scores lower than 0 or higher than 10 are
   accepted. */

#include "Utility.h"

/* Prototypes: Get judge data, Calculate score,
               Find lowest, Find highest */
void getJudgeData(double &, string);
void calcScore(double, double, double, double, double, double);
int findLowest(double, double, double, double, double, double);
int findHighest(double, double, double, double, double, double);

int main()
{
   /* Variables: Scores one through five */
   double refScoreOne = 0,
          refScoreTwo = 0,
          refScoreThree = 0,
          refScoreFour = 0,
          refScoreFive = 0,
          calcAvgScore = 0;

   /* Variable: Judge name */
   string judgeName = " ";

   /* Display: Welcome message
      Get: Judge scores */
   cout << "\t\tYAMAHA ANNUAL POPULAR CONTEST FINALS\n\n"
        << "Welcome to the annual YAMAHA Popular Contest!\n"
        << "Our judges are eager to vote on the hottest new talents\n"
        << "and already famous Stars in the Popular Music Scene of\n"
        << "today.\n\n"
        << "Please try hard!\n\n";

   /* Call: getJudgeData */
   getJudgeData(refScoreOne, "N. Chino");
   getJudgeData(refScoreTwo, "A. Nakano");
   getJudgeData(refScoreThree, "Y. Ono");
   getJudgeData(refScoreFour, "K. Watanabe");
   getJudgeData(refScoreFive, "H. Yasutake");

   /* Call: calcScore */
   calcScore(refScoreOne, refScoreTwo, refScoreThree, refScoreFour,
             refScoreFive, calcAvgScore);

   pauseSystem();
   return 0;
}

/* **********************************************************
   Definition: getJudgeData

   This function asks the user for a judge's score, stores it
   in a reference parameter variable, and validates it. It is
   called by main once for each of the five judges.
   ********************************************************** */

void getJudgeData(double &judgeScore, string judgeName)
{
   /* Get: Judge score */
   cout << "" << judgeName << "'s Vote: ";
   cin >> judgeScore;

   /* Validate: Input */
   while (judgeScore <= 0 || judgeScore > 10)
   {
      cout << "\nJudge " << judgeName << " score could not be\n"
           << "evaluated. It was either below 0 or higher than 10.\n"
           << "Please repeat your vote: ";
      cin >> judgeScore;

      /* Catch: Infinite loop */
      cin.clear();
      cin.ignore();
   }
}

/* **********************************************************
   Definition: calcScore

   This function calculates and displays the average of the
   three test scores that remain after dropping the highest
   and lowest scores the performer received. This function is
   called once by main and passes the five scores.
   ********************************************************** */

void calcScore(double avgScoreOne, double avgScoreTwo,
               double avgScoreThree, double avgScoreFour,
               double avgScoreFive, double avgScore)
{
   /* Variables: Lowest score, Highest score */
   double highestScore = 0.0,
          lowestScore = 0.0;

   /* Call: findLowest */
   lowestScore = findLowest(avgScoreOne, avgScoreTwo, avgScoreThree,
      avgScoreFour, avgScoreFive, lowestScore);

   /* Call: findHighest */
   highestScore = findHighest(avgScoreOne, avgScoreTwo, avgScoreThree,
      avgScoreFour, avgScoreFive, highestScore);

   /* Calculate: The average score */
   avgScore = (avgScoreOne + avgScoreTwo + avgScoreThree +
               avgScoreFour + avgScoreFive - highestScore - lowestScore) / 3;

   /* Set up: Numeric output formatting */
   cout << fixed << showpoint << setprecision(1);

   /* Display: The average of the remaining three scores */
   cout << "\nAfter calculating the scores of our judges,\n"
        << "we can finally announce the winners of this years\n"
        << "YAMAHA Popular Contest: 'Hide and Rosanna'\n"
        << "They won with an average score of: " << avgScore
        << "\n\nCongratulations!\n";
}

/* **********************************************************
   Definition: findLowest

   This function finds and returns the lowest of five scores
   passed to it.
   ********************************************************** */

int findLowest(double lowestRefOne, double lowestRefTwo,
               double lowestRefThree, double lowestRefFour,
               double lowestRefFive, double lowestRefScore)
{
   /* lowestRefScore is initialized to lowestRefOne to have a
      starting value for comparing the other scores */
   lowestRefScore = lowestRefOne;

   /* These conditional statements determine the lowest of the
      five scores to be dropped */
   lowestRefScore = lowestRefTwo < lowestRefScore ?
                    lowestRefTwo : lowestRefScore;
   lowestRefScore = lowestRefThree < lowestRefScore ?
                    lowestRefThree : lowestRefScore;
   lowestRefScore = lowestRefFour < lowestRefScore ?
                    lowestRefFour : lowestRefScore;
   lowestRefScore = lowestRefFive < lowestRefScore ?
                    lowestRefFive : lowestRefScore;

   /* Display: The lowest score that will be dropped */
   cout << "\nThe lowest score was " << lowestRefScore
        << " and has not been taken into account.\n";

   /* Return: lowestRefScore is demoted before it is returned
              to calcScore */
   return (int)lowestRefScore;
}

/* **********************************************************
   Definition: findHighest

   This function finds and returns the highest of five scores
   passed to it.                                            
   ********************************************************** */

int findHighest(double highestRefOne, double highestRefTwo,
                double highestRefThree, double highestRefFour,
                double highestRefFive, double highestRefScore)
{
   /* Highest score is initialized to highestRefOne as an
      initial value for determining the highest score that
      will be dropped */
   highestRefScore = highestRefOne;
 
   /* These conditional statements determine the highest
       of the five scores to be dropped */
   highestRefScore = highestRefTwo > highestRefOne ?
                     highestRefTwo : highestRefScore;
   highestRefScore = highestRefThree > highestRefScore ?
                     highestRefThree : highestRefScore;
   highestRefScore = highestRefFour > highestRefScore ?
                     highestRefFour : highestRefScore;
   highestRefScore = highestRefFive > highestRefScore ?
                     highestRefFive : highestRefScore;

   /* Display: The highest score that will be dropped */
   cout << "The highest score was " << highestRefScore
      << " and has not been taken into account.\n";

   /* Return: highestRefScore is demoted to int before returning
              it to calcscore to calcScore */
   return (int)highestRefScore;
}

Programming Challenge 6.11 - Lowest Score Drop

/* Lowest Score Drop - This program calculates the average of a group of
   test scores, where the lowest score in the group is dropped. It uses
   the following functions:
  
   * void getScore()
   * void calcAverage()
   * int findLowest()
  
   Input Validation: No test scores lower than 0 or higher than 100 are
   accepted. */

#include "Utility.h"

/* Prototypes: Get score, Calculate average, Find lowest */
void getScore(int &);
void calcAverage (int, int, int, int, int);
int findLowest (int, int, int, int, int);

int main()
{
   /* Variables: Scores 1 through 5 */
   int scoreOne = 0,
       scoreTwo = 0,
       scoreThree = 0,
       scoreFour = 0,
       scoreFive = 0;

   /* Display: Information */
   cout << "\t\tAverage Test Score Calculator\n\n"
        << "This application allows you to enter five test scores,\n"
        << "to find the lowest score, which will be dropped, before\n"
        << "the average is calculated and displayed.\n\n";

   /* Call: getScore, the values are stored in scoreOne through scoreFive */
   getScore(scoreOne);
   getScore(scoreTwo);
   getScore(scoreThree);
   getScore(scoreFour);
   getScore(scoreFive);

   /* Call: calcAverage */
   calcAverage(scoreOne, scoreTwo, scoreThree, scoreFour, scoreFive);

   pauseSystem();
   return 0;
}

/* **********************************************************
   Definition: getScore

   This function asks the user for a test score, stores it in
   a reference parameter variable, and validates it. It is
   called by main once for each of the five scores entered.
   ********************************************************** */

void getScore(int &scores)
{
   static int cnt = 1;

      /* Get: Scores */
      cout << "Please Enter Test Score " << (cnt++) << ": ";
       cin >> scores;

      /* Validation: If the user enters a number lower than 1
         or greater than 100, he or she will receive a message
         and be asked to enter the score again */
      while (scores < 0 || scores > 100)
      {
         cout << "\nIt seems that you have entered a number that\n"
              << "was below 1 or above 100. Please enter a valid\n"
              << "test score " << (cnt - 1) << ": ";
         cin >> scores;
      }
}

/* **********************************************************
   Definition: calcAverage

   This function calculates and displays the average of the
   four highest scores. It is called once by main and gets
   passed the five test scores.
   ********************************************************** */

void calcAverage(int avgScoreOne, int avgScoreTwo, int avgScoreThree,
                 int avgScoreFour, int avgScoreFive)
{
   /* Variables: Average score, Drop lowest */
   int avgScore = 0,
       dropLowest = 0;

   /* Call: findLowest, pass the test scores as arguments, and get
            the lowest test score */
   dropLowest = findLowest(avgScoreOne, avgScoreTwo, avgScoreThree,
                            avgScoreFour, avgScoreFive);

   /* Calculate: The average test score */
   avgScore = (avgScoreOne + avgScoreTwo + avgScoreThree +
               avgScoreFour + avgScoreFive - dropLowest) / 4;

   /* Display: The formatted average test score */
   cout << "\nYour average test score is: " << avgScore << endl;
}

/* **********************************************************
   Definition: findLowest

   This function finds and returns the lowest of the five
   scores passed to it. It is called by calcAverage, which
   uses the function to determine which of the five scores
   to drop.
   ********************************************************** */

int findLowest(int lowestScoreOne, int lowestScoreTwo,
               int lowestScoreThree, int lowestScoreFour,
               int lowestScoreFive)
{
   /* Variable: Lowest score initialized to lowestScoreOne */
   int lowestScore = lowestScoreOne;
 
   /* These conditional statements determine the lowest test score */
   lowestScore = lowestScoreTwo < lowestScore ? lowestScoreTwo : lowestScore;
   lowestScore = lowestScoreThree < lowestScore ? lowestScoreThree : lowestScore;
   lowestScore = lowestScoreFour < lowestScore ? lowestScoreFour : lowestScore;
   lowestScore = lowestScoreFive < lowestScore ? lowestScoreFive : lowestScore;
  
   /* Display: The lowest score that will be dropped */
   cout << "\nThe lowest test score out of five was " << lowestScore
        << "\nand will be dropped from the calculation.\n";
  
   /* Return: The lowest test score */
   return lowestScore;
}

Update

Instead of publishing a freshly solved Programming Challenge, I had to change two of my previous entries:

Programming Challenge 6.3 - Winning Division
Programming Challenge 6.4 - Safest Driving Area

Even though both challenges were technically solved and worked correctly as they were, my solution was not correct. The task was to pass the division name to the function in Challenge 6.3, and in Challenge 6.4 it should have been the region names. This did not happen, so I decided to republish both.

Had it not been for the fact that I am stuck at my current Challenge, looking at the solved ones to find a solution, I would probably have never discover it ... Glad that I did, so I could correct these most embarrassing mistakes ... (Sorry for this!)

Now it is time for a little Espresso break, and then back to work on the challenge that is currently fighting me with teeth and claws! 

Wednesday, January 4, 2017

Programming Challenge 6.10 - Future Value

/* Future Value - Suppose you have a certain amount of money in a
   savings account that earns compound monthly interest, and you
   want to calculate the amount that you will have after a specific
   number of months. The formula, which is known as the future value
   formula, is:
  
   * F = P x (1 + i)^t
  
   The terms are as follows:

   * F is the future value of the account after the specified
     time period.
   * P is the present value of the account.
   * i is the monthly interest.
   * t is the number of months.

   This program uses a function named futureValue to perform this
   calculation. It prompts the user to enter the account's present
   value, monthly interest rate, and the number of months that the
   money will be left in the account. The program displays the
   account's future value. */

/* Prototype: Future Value */
double futureValue (double, double, int);

#include "Utility.h"

int main()
{
   /* Constants: Begin, Try again, Quit */
   const int BEGIN = 1,
      AGAIN = 2,
      QUIT = 3;

   /* Variable: Selection */
   int selection = 0;

   /* Variables: Present value, Monthly interest rate, Future value */
   double presentVal = 0.0,
      monthlyIntRate = 0.0,
      futureVal = 0.0;

   /* Variable: Number of months */
   int numMonths = 0;

   /* Display: Introduction */
   cout << "\t\tAshikaga Bank - Personal Financal Planner\n\n"
      << "Valued customer,\n\n"
      << "Suppose you have a certain amount of money on your savings\n"
      << "account that earns compound monthly interest, and you wish\n"
      << "to know the amount of money you will have after a specific\n"
      << "number of months.\n\n"
      << "For instance:\n"
      << "If you have $10,000 in your savings account, after 120\n"
      << "months, with a monthly interest rate of 9%, your account's\n"
      << "future value would be $24,513.57\n\n"
      << "This program calculates the so called future value, or amount\n"
      << "of money you will have in your savings account in the future.\n"
      << "It also allows you to experiment with the following values to\n"
      << "get different results:\n\n"
      << "* Present Value: The amount of money currently on your account\n"
      << "* Monthly Interest Rate: For instance 9.0%\n"
      << "* The number of months the money will be left alone to earn\n"
      << "  monthly compound interest, 120 months would be 10 years.\n\n";

   do
   {
   /* Display: Menu
      Get: User selection */
   cout << "1. Begin\n"
        << "2. Try again\n"
        << "3. Quit.\n";
   cin >> selection;
 
      /* Validate: Menu selection */
      while (selection < 1 || selection > 3)
      {
         cout << "Please select a valid menu item: ";
         cin >> selection;
      }

      /* As long as the user does not wish to quit the program,
         he or she is asked to enter the present value, monthly
         interest rate, and number of months */
      if (selection != QUIT)
      {
         cout << "\nStep 1: Enter the present value of your\n"
            << "savings account: $ ";
         cin >> presentVal;

         /* Validate: Input */
         while (presentVal <= 0)
         {
            cout << "\nValued customer, you seem to have entered a negative\n"
               << "number as the present value. Only positive values are\n"
               << "accepted.\n"
               << "Please repeat your input: $ ";
            cin >> presentVal;
         }

         cout << "\nStep 2: Now enter the monthly interest rate that\n"
            << "applies to your savings plan (ex: 9.0%): % ";
         cin >> monthlyIntRate;

         /* Validate: Input */
         while (monthlyIntRate <= 0 || monthlyIntRate > 100)
         {
            cout << "\nValued customer, the monthly interest rate can\n"
               << "not be lower than 1, and not greater than 100%.\n"
               << "Please repeat your input: % ";
            cin >> monthlyIntRate;
         }

         cout << "\nStep 3: The last thing you need to enter is the number\n"
            << "of months your money should earn interest. (ex: 120): ";
         cin >> numMonths;

         /* Validate: Input */
         while (numMonths <= 0)
         {
            cout << "\nValued customer, you have to enter a positive value "
               << "for months.\n"
               << "Please repeat your input: ";
            cin >> numMonths;
         }

         monthlyIntRate /= 100;

         /* Call: futureValue */
         futureVal = futureValue(presentVal, monthlyIntRate, numMonths);

         /* Set up: Numeric output formattingi */
         cout << fixed << showpoint << setprecision(2);

         /* Display: Future value */
         cout << "\nFuture Value Calculator - Result\n\n"
            << "Valued customer,\n\n"
            << "According to the information you provided, you currently\n"
            << "have $ " << presentVal << " in your account. "
            << "After a period of " << numMonths
            << "\nmonths, at a monthly interest rate of " << (monthlyIntRate * 100)
            << "% your future\n"
            << "account value will be $ " << futureVal << "\n\n";
      }

      if (selection == QUIT)
      {
         cout << "\nValued customer,\n\n"
              << "Thank you for your trust in our services.\n"
              << "We wish you a successful future, and hope\n"
              << "that you will return soon.\n"
              << "Your Ashikaga Bank Team\n\n";
      }
   } while (selection != QUIT);

    pauseSystem();
    return 0;
}

/* **********************************************************
   Defintion: futureValue

   This function accepts the account's present value, monthly
   interest rate, and number of months as arguments, it then
   calculates and returns the future value of the account,
   after the specified number of months.
   ********************************************************** */

double futureValue(double presentVal, double monthlyIntRate,
                   int numMonths)
{
   /* Variable: Future value */
   double futureVal = 0.0;

   /* Calculation: The future value of the savings account */
   futureVal = presentVal * pow(1.0 + (monthlyIntRate / 12), numMonths);

   /* Return: The future value */
   return futureVal;
}

Programming Challenge 6.9 - Present Value

/* Present Value - Suppose you want to deposit a certain amount of money
   into a savings account and then leave it alone to draw interest for
   the next 10 years. At the end of 10 years you would like to have
   $10,000 in the account. How much do you need to deposit today to
   make that happen? The following formula can be used to find out.
 
   * P = F / (1 + r)^n
 
   The terms in the formula are as follows:
 
   * P is the present value, or the amount you need to deposit today.
   * F is the future value that you want in the account. (In this case,
     F is $10,000.
   * r is the annual interest rate.
   * n is the number of years you plan to let the money sit in the
          account.
           
   This program uses a function named presentValue that performs
   this calculation. The program is demonstrated by letting the
   user experiment with different values for the formula's terms. */

#include "Utility.h"

/* Prototype: Present value */
double presentValue(double, double, int);

int main()
{
   /* Constants: Begin, Try again, Quit */
   const int BEGIN = 1,
             AGAIN = 2,
             QUIT = 3;

   /* Variable: Selection */
   int selection = 0;

   /* Variables: Future Value, Annual Interest Rate, PresentValue */
   double futureValue = 0.0,
          annualIntRate = 0.0,
          presentVal = 0.0;

   /* Variable: Number of years */
   int numYears = 0;

   /* Display: Introduction */
   cout << "\t\tAshikaga Bank - Personal Financal Planner\n\n"
        << "Valued customer,\n\n"
        << "Suppose you wish to know how much money you need to deposit\n"
        << "today, to receive the sum you wish some time in the future.\n\n"
        << "For instance:\n"
        << "If you wish to have $10,000 in your savings account after 10\n"
        << "years, with an interest rate of 5.25% annualy, you would have\n"
        << "to invest a certain amount of money today.\n\n"
        << "This program calculates the so called present value, or amount\n"
        << "of money you need to put into your savings account today, to\n"
        << "receive the sum of money you wish for in the future. It also\n"
        << "allows you to experiment with the following values to get\n"
        << "different results:\n\n"
        << "* Future Value: The value you wish to receive\n"
        << "* Annual Interest Rate: For instance 5.25%\n"
        << "* The number of years you plan to let the money\n"
        << "  alone on your account to earn interest.\n\n";

   do
   {
      /* Display: Menu
         Get: User selection */
      cout << "1. Begin\n"
           << "2. Try again\n"
           << "3. Quit.\n";
      cin >> selection;

      /* Validate: Menu selection */
      while (selection < 1 || selection > 3)
      {
         cout << "Please select a valid menu item: ";
         cin >> selection;
      }

      /* As long as the user does not wish to quit experimenting
      with different values, he or she is asked to enter the future
      value, the annual interest rate, and number of years. */
      if (selection != QUIT)
      {
         cout << "\nStep 1: Enter the future value you want in your\n"
            << "savings account: $ ";
         cin >> futureValue;

         /* Validate: Input */
         while (futureValue <= 0)
         {
            cout << "\nValued customer, you seem to have entered a\n"
                 << "negative number for future value. Please repeat\n"
                 << "your input (positive values only): $ ";
            cin >> futureValue;
         }

         cout << "\nStep 2: Now enter the annual interest rate that\n"
            << "applies to your savings plan (ex: 5.7): % ";
         cin >> annualIntRate;

         /* Validate: Input */
         while (annualIntRate <= 0 || annualIntRate > 100)
         {
            cout << "\nValued customer, the annual interest rate can not\n"
                 << "be lower than 1, and not greater than 100%.\n"
                 << "Please repeat your input: % ";
            cin >> annualIntRate;
         }

         cout << "\nStep 3: The last thing you need to enter is the\n"
            << "number of years you plan to let the money sit in\n"
            << "your savings account: ";
         cin >> numYears;

         /* Validate: Input */
         while (numYears <= 0)
         {
            cout << "\nValued customer, the input for years must be\n"
                 << "both positive, and at least equal to 1 or above.\n"
                 << "Please repeat your input: ";
            cin >> numYears;
         }

         annualIntRate /= 100;

         /* Call: presentValue */
         presentVal = presentValue(futureValue, annualIntRate, numYears);

         /* Set up: Numeric output formatting */
         cout << fixed << showpoint << setprecision(2);

         /* Display: Present value */
         cout << "Present Value Calculator - Result\n\n"
              << "\nValued customer,\n\n"
              << "According to the information you provided, you would\n"
              << "need to put $" << presentVal << " into your "
              << "account today to earn\n"
              << "$" << futureValue
              << " after " << numYears << " years "
              << " at an annual interest rate\n"
              << "of " << (annualIntRate * 100) << "%\n\n";
      }

      /* Display: When the user decides to quit, a message is displayed */
      if (selection == QUIT)
      {
         cout << "\nValued Customer,\n\n"
              << "Thank you for your trust in our services.\n"
              << "We wish you a successful future, and hope\n"
              << "that you will return soon.\n"
              << "Your Ashikaga Bank Team\n\n";
      }
   } while (selection != QUIT);

   pauseSystem();
   return 0;
}

/* **********************************************************
   Definition: presentValue

   This function accepts the future value (F), the annual
   interest rate (r), and number of years (n) as arguments.
   It returns the present value, which is the amount needed
   to deposit today.
   ********************************************************** */

double presentValue(double futureValue, double annualIntRate,
                    int numYears)
{
   /* Variable: Present Value */
   double presentVal = 0.0;

   /* Calculation: The present value */
   presentVal = futureValue / pow(1.0 + annualIntRate, numYears);

   /* Return: The present value */
   return presentVal;
}

Tuesday, January 3, 2017

Programming Challenge 6.8 - Coin Toss

/* Coin Toss - This program uses the function:

* coinToss()

It is demonstrated by calling the function in this program which
asks the user how many many times the coin should be tossed and
then simluates the tossing of the coin that number of times. */

#include "Utility.h"

/* Prototype: Coin Toss */
void coinToss(int);

int main()
{
   /* Variable: Throw Coin */
   int numTosses = 0;

   /* Display: Introduction
      Get: The number of coin tosses from the user
      Call: coinToss */
   cout << "\t\tCoin Toss Simulator\n\n"
        << "Deciding between two things isn't always easy.\n"
        << "Cake or Cabbage? Right or Left? New Clothes or\n"
        << "Second Hand? Which shall it be?\n"
        << "This program is the ideal solution to this very\n"
        << "problem! Simply enter the number of times a coin\n"
        << "should be tossed, and let the outcome decide.\n\n"
        << "How many times should the coin be tossed? ";
   cin >> numTosses;

   /* Input Validation: If the input is 0 or negative, the user
      gets a message to try again */
   while (numTosses <= 0)
   {
      cout << "It seems that you entered 0 or a negative\n"
           << "number which is invalid. Please try again.\n"
           << "How many times should the coin be tossed? ";
      cin >> numTosses;
   }

   coinToss(numTosses);

   pauseSystem();
   return 0;
}

/* **********************************************************
   Definition: coinToss

   This function accepts a number it gets from user input as
   argument, and generates a random number in the range of 1
   through 2.

   * If the random number is 1, "heads" is displayed.
   * If the random number is 2, "tails" is displayed.
   ********************************************************** */

void coinToss(int coinTosses)
{
   /* Constants: Heads, Tails */
   const int HEADS = 1,
             TAILS = 2;

   /* Variable: randomThrow */
   int randomThrow = 0;

   /* Set: Seed of the random number generator*/
   srand((unsigned int)time(NULL));

   /* Display: Table Header */
   cout << "\nThrow No: " << "\tWas: ";
   cout << "\n---------------------\n";

   /* While this loop iterates, randomThrow will produce random
      numbers, the conditional statement determines whether the
      throw was heads or tails, and the result is displayed */
   for (int throws = 1; throws <= coinTosses; throws++)
   {
      randomThrow = (rand() % (TAILS - HEADS + 1)) + HEADS;

      randomThrow == HEADS ? cout << throws << "\t\tHeads\n" :
                             cout << throws << "\t\tTails\n";
   }
}

Programming Challenge 6.7 - Celsius Temperature Table

/* Celsius Temperature Table - The formula for converting a temperature
   from Fahrenheit to Celsius is:

   * C = 5/9 (F-32)

   Where F is the Fahrenheit temperature and C is the Celsius temperature.

   This program uses the following function:

   * celsius()

   The function is demonstrated by calling it in a loop that displays a
   table of the Fahrenheit temperatures 0 through 20 and their Celsius
   equivalents. */

#include "Utility.h"

/* Prototype: Celsius */
double celsius (double);

int main()
{
   /* Variable: Fahrenheit */
   double tempFahrenheit = 0.0,
          tempCelsius = 0.0;

   /* Set Up: Numeric output formatting */
   cout << fixed << showpoint << setprecision(1);

   /* Display: Introduction */
   cout << "\t\tCelsius Temperature Table - Function Demo\n\n"
        << "This program converts a range of temperatures in degree\n"
        << "Fahrenheit to degree Celsius with a custom function,\n"
        << "which is demonstrated here.\n\n";

   /* Display: Table header */
   cout << "Temperature Fahrenheit:" << "\t\t"
        << "Temperature Celsius:\n"
        << "----------------------\t\t-------------------\n";

   /* This loop calls celsius, which converts fahrenheit to
      celsius, which is returned and stored in the variable
      tempCelsius, then displays the result of the conversion
      process */
   while (tempFahrenheit <= 20)
   {
      tempCelsius = celsius(tempFahrenheit);

      cout << setw(6) << left << tempFahrenheit
           << "\t\t\t\t"
           << setw(4) << right << tempCelsius << endl;

      tempFahrenheit++;
   }

   pauseSystem();
   return 0;
}

/* **********************************************************
   Definition: celsius

   This function accepts a Fahrenheit temperature as an
   argument, and returns the temperature, converted to
   Celsius.
   ********************************************************** */

double celsius(double fToCelsius)
{
   /* Calculation: fToCelsius gets the fahrenheit temperature
      from tempFahrenheit as argument, then converts it to °C
      by way of the formula °C = (F - 32) / 1.8 (where 1.8 is
      the fraction 9/5 converted to decimal) */
      fToCelsius = (fToCelsius - 32) / 1.8;

   /* Return: The celsius temperature to tempCelsius in main */
   return fToCelsius;
}