Saturday, December 24, 2016

Switching language

Als erstes möchte ich all meinen Besucherinnen und Besuchern Frohe Weihnachten, Merry Christimas, Joyeux Noël, Jwaye Nwèl, Geseënde Kersfees, メリークリスマス ... (Meri kurisumasu for those of you who happen not to speak, and/or understand, Japanese) wünschen.

That said, the small number of blog posts not consisting of code were posted in german (if you haven't guessed.) Since most of my visitors are from the U.S. (or other english speaking countries) , i decided to switch to 日本語 (Nihongo - Japanese language), so you be totally left in the dark what exactly i write here, or will in my source code comments. (joking of course).

As of now i will keep posting in English, to annoy the world with my ramblings about this and that, and all the other things. ;)

Before publishing this post, i think it is also about time to thank those kind souls who took the time to give my posts +'s, Thank you, 本当にありがとうございます。 (Truly appreciated!) Ok, ok, enough Japanese already! 

Have a pleasant evening, all and everyone, and check back for more (truly ugly, badly written (you be my guest and fill in some more good things that can be said about it), C++ Code. ;-)

Programming Challenge 5.17 - Sales Bar Chart

/* Sales Bar Chart - This program asks the user to enter today's sales for
   five stores. The program displays a bar graph comparing each store's
   sales. A bar chart in the bar graph is displaying a row of asterisks.
   Each asterisk represents $100 of sales.

   Example output:

   * Enter today's sales for store 1: 1000 [Enter]
   * Enter today's sales for store 2: 1200 [Enter]
   * Enter today's sales for store 3: 1800 [Enter]
   * Enter today's sales for store 4:  800 [Enter]
   * Enter today's sales for store 5: 1900 [Enter]

   SALES BAR CHART
   (Each *= $100)
   Store 1: **********
   Store 2: ************
   Store 3: ******************
   Store 4: ********
   Store 5: ******************* */

#include "Utility.h"

int main()
{
    /* Constant: Maximum number of stores */
    const int STORES_MAX = 5;

    /* Variables: Number of stores (counter variable), Bar chart
       (counter variable) */
    int barChart = 1,
        numStores = 1;

    /* Variables: Stores, Sales figure (1 ... 5) */
    double salesFigure = 0,
           salesFigure2 = 0,
           salesFigure3 = 0,
           salesFigure4 = 0,
           salesFigure5 = 0;

    /* For loop: As long as the number of stores is lower than or equal
       to STORES_MAX, this loop will iterate */
    for (numStores = 1; numStores <= STORES_MAX; numStores++)
    {
        /* Display: Ask the user to enter data for each store */
        cout << "Enter today's sales figure for store "
            << numStores << ": ";

        /* Switch Statement::Input: Until the sales figures for stores 1
           to 5 are entered, this statement will be executed */
        switch (numStores)
        {
        case 1:
            cin >> salesFigure;
            salesFigure /= 100;
            break;

        case 2:
            cin >> salesFigure2;
            salesFigure2 /= 100;
            break;

        case 3:
            cin >> salesFigure3;
            salesFigure3 /= 100;
            break;

        case 4:
            cin >> salesFigure4;
            salesFigure4 /= 100;
            break;

        case 5:
            cin >> salesFigure5;
            salesFigure5 /= 100;
            break;
        }
    }

    /* Display: Table header */
    cout << "\nSales Bar Chart\n";
    cout << "(Each * = $100)";

    /* For loop: As long as the store number is lower than or equal to
       STORES_MAX (5), this loop will iterate */
    for (numStores = 1; numStores <= STORES_MAX; numStores++)
    {
        /* Display: Store number */
        cout << "\nStore " << numStores << ":";
      
        /* Nested For loop: As long as bar chart is smaller than
           or equal to sales figure 1 through 5, and the store
           number equals store 1 through 5, this loop will iterate */
        for (barChart = 1;
             barChart <= salesFigure && numStores == 1 ||
             barChart <= salesFigure2 && numStores == 2 ||
             barChart <= salesFigure3 && numStores == 3 ||
             barChart <= salesFigure4 && numStores == 4 ||
             barChart <= salesFigure5 && numStores == 5;
             barChart++)
        {
            cout << '*';
        }  
    }
    cout << endl;

    pauseSystem();
    return 0;
}

Thursday, December 22, 2016

Programming Challenge 5.16 - Savings Account Balance

/* Savings Account Balance - This program calculates the balance of a savings
   account at the end of a period of time. It asks the user for the annual
   interest rate, the starting balance, and the number of months that have
   passed since the account was established. A loop iterates once for every
   month, performing the following:

   * The user is asked for the amount deposited into the account during the
      month. This amount is added to the balance.

      Input Validation: No negative numbers are accepted.

   * The user is asked for the amount withdrawn from the account during the
     month. This amount is subtracted from the balance.

     Input Validation: No negative numbers are accepted.

   * Calculating the monthly interest:

     The monthly interest rate is the annual interest rate divided by twelve.
     The monhtly interest rate is multiplied by the balance, and the result is
     added to the balance.

   After the last iteration, the program displays the ending balance, the total
   amount of deposits, the total amount of withdrawals, and the total interest
   earned.

   Notice: If, at any point, a negative balance is calculated, a message will
   be displayed, indicating that the account has been closed and the loop will
   terminate. */

#include "Utility.h"

int main()
{
    /* Constant: Maximum annual interest rate */
    const double ANNUAL_INTEREST_MAX = 15;

    /* Variable: Months (counter variable), Months passed */
    int months = 1,
        monthsPassed = 0;

    /* Variables: Starting Balance, Annual interest rate, Monthly interest
       rate, Account Balance (accumulator variable), Account balance total,
       Monthly deposits, Monthly deposits total, Monthly withdrawals total
       (accumulator variable), Monthly balance total,
       (accumulator variable), Monthly interest earned, Deposits total,
       Withdrawals total, Interest earned total */
    double startingBalance = 0,
           annualInterestRate = 0,
           accountBalance = 0,
           accountBalanceTotal = 0,
           monthlyInterest = 0,
           interestRate = 0,
           monthlyInterestRate = 0,
           monthlyDeposits = 0,
           monthlyDepositsTotal = 0,
           monthlyWithdrawals = 0,
           monthlyWithdrawalsTotal = 0,
           monthlyInterestEarned = 0,
           monthlyBalanceTotal = 0,
           depositsTotal = 0,
           withdrawalsTotal = 0,
           interestEarnedTotal = 0;  

    /* Display: Information */
    cout << "\t\tAshikaga Bank: Personal Account Balance Manager\n\n";

    /* Input::Ask the user for: The starting balance of the users bank
    account, the annual interest rate, the number of months have passed
    since the account was established */
    cout << "What was the starting balance of your account?\n"
        << "Starting Balance: $ ";
    cin >> accountBalance;

    /* While loop::Input Validation: As long as the starting balance entered
    by the user is below or equal to 0, this loop will iterate */
    while (accountBalance <= 0)
    {
        /* Display: Error message */
        cout << "Error: The Starting Balance has to be a positive value.\n";

        /* Ask again: */
        cout << "Starting Balance: $ ";
        cin >> accountBalance;
    }

    cout << "What is the annual interest rate?\n"
        << "Annual Interest Rate: % ";
    cin >> annualInterestRate;

    /* While loop::Input Validation: While the annual interest rate entered
    by the user is below or equal to 0, or above ANNUAL_INTEREST_MAX (4.25),
    this loop will iterate */
    while (annualInterestRate <= 0 || annualInterestRate > ANNUAL_INTEREST_MAX)
    {
        /* Display: Error message */
        cout << "Error: The Annual Interest Rate has to be a positive value\n"
            << "above 0 and below or equal to %15.00.\n";

        /* Ask again: */
        cout << "Starting Balance: $ ";
        cin >> annualInterestRate;
    }

    cout << "How much time has passed since your account was established?\n"
         << "Months Passed: ";
    cin >> monthsPassed;

    /* While loop::Input Validation: While months passed entered by the user
       is below or equal to 0, this loop will iterate */
    while (monthsPassed <= 0)
    {
        /* Display: Error message */
        cout << "Error: The amount of months passed can not be negative!\n";

        /* Ask again: */
        cout << "Months Passed: ";
        cin >> monthsPassed;
    }

    /* For loop: As long as months is lower than or equal to months passed,
       this loop will iterate */
    for (months; months <= monthsPassed; months++)
    {
        /* Nested While loop: While months is smaller than or equal to
           months passed, and the account balance is not negative,
           this loop will iterate */
        while (months <= monthsPassed && (!(accountBalance < 0)))
        {
            /* Input::Ask the user for: His or her monthly deposits, his or
            her monthly withdrawals */
            cout << "\nHow much money have you deposited in month " << months
                << " in total?\n"
                << "Monthly Deposit: $ ";
            cin >> monthlyDeposits;

            /* Nested While loop: While the customer enters a negative
               number for his or her monthly deposits, this loop will
               iterate */
            while (monthlyDeposits < 0)
            {
                /* Display: Error message */
                cout << "\nError: Monthly deposits have to be positive,\n"
                     << "or above, or equal to 0, if no deposits were\n"
                     << "made in the month you wish to enter data for.\n";

                /* Ask again: */
                cout << "\nHow much money have you deposited in month " << months
                    << " in total?\n"
                    << "Monthly Deposit: $ ";
                cin >> monthlyDeposits;
            }

            cout << "\nHow much money have you withdrawn in month " << months
                << " in total?\n"
                << "Monthly Withdrawals: $ ";
            cin >> monthlyWithdrawals;
   
            /* Nested While loop: While the customer enters a negative
            number for his or her monthly withdrawals, this loop will
            iterate */
            while (monthlyWithdrawals < 0)
            {
                /* Display: Error message */
                cout << "\nError: Monthly withdrawals have to be positive,\n"
                     << "or above, or equal to 0, if no withdrawals have\n"
                     << "occured in the month you wish to enter data for.\n";

                /* Ask again: */
                cout << "\nHow much money have you withdrawn in month "
                     << months << " in total?\n"
                     << "Monthly Withdrawals: $ ";
                cin >> monthlyWithdrawals;
            }

            /* Accumulating: Monthly deposits (add to the account balance),
               Monthly withdrawals (deduct from the account balance) */
            accountBalance += monthlyDeposits;
            accountBalance -= monthlyWithdrawals;

            /* Calculations: Monthly interest rate:
               To get the fraction of the total interest rate, 4.25 = 0.0425,
               the annual interest rate is divided by 100 and by the amount
               of months in a year */
               monthlyInterestRate = (annualInterestRate / 12.0) / 100.0;

            /* Interest rate formula: Monthly interest rate = account balance *
               monthly interest rate * (months passed / 12.0) / 100.0 */       
            interestRate = accountBalance * monthlyInterestRate *
                          (monthsPassed / 12.0);
            monthlyInterest = accountBalance * monthlyInterestRate *
                          (monthsPassed / 12.0);

            /* Accumulating: Total monthly deposits, Total monthly withdrawals,
               Total monthly interest earned, Total monthly balance */
            monthlyDepositsTotal += monthlyDeposits;
            monthlyWithdrawalsTotal -= monthlyWithdrawals;
            monthlyInterestEarned += monthlyInterest;
            monthlyBalanceTotal = accountBalance + monthlyInterestEarned;

            /* Accumulating: Total Deposits, Total withdrawals, Total
               Interest Earned, Total account balance */
            depositsTotal += monthlyDeposits;
            withdrawalsTotal -= monthlyWithdrawals;
            interestEarnedTotal += interestRate;
            accountBalanceTotal = accountBalance + interestEarnedTotal;

            /* If Statement: If the account balance is negative, or the
            total monthly balance is negative, or the monthly withdrawals
            are greater than the monthly deposits, and the monthly withdrawals
            are greater than the monthly account balance the loop will
            terminate */
            if (accountBalance < 0 || monthlyBalanceTotal < 0 ||
                monthlyWithdrawals > monthlyDeposits &&
                monthlyWithdrawals > monthlyBalanceTotal)
            {
                cout << "\nValued customer,\n\n"
                     << "We are utmost sorry to have to inform you about the sad\n"
                     << "event, that your bank account was for some unknown reason\n"
                     << "overdrawn, and had to be terminated.\n"
                     << "If you wish to aquire further information about this event,\n"
                     << "or you feel that this was a failure on our side or a third\n"
                     << "party we have no control over, please do not hesitate to call\n"
                     << "us. Our hotlines are open for you 24/7.\n"
                     << "It would also be a pleasure for us, should you give us the\n"
                     << "opportunity to clarify this sad situation with you personally,\n"
                     << "to visit us during our regular service hours. We will see to it,\n"
                     << "that this problem will be resolved to your utmost satisfaction.\n"
                     << "Thank you for your understanding,\n\n"
                     << "Your Ashikaga Bank Team\n";

                pauseSystem();
                return 0;
            }

                /* Display: Formatted monthly output of the account balance sheet */
                cout << fixed << showpoint << setprecision(2);
                cout << "\n\t\tAshikaga Bank - Monthly Account Balance Sheet\n";
                cout << "--------------------------------------------------------------------\n";
                cout << "Month: " << months << "\n";
                cout << "\nMonthly Deposits Total:\t\t\t\t\t $ " << setw(9) << right
                    << monthlyDepositsTotal << endl;
                cout << "Monthly Withdrawals Total:\t\t\t\t $ " << setw(9) << right
                    << monthlyWithdrawalsTotal << endl;
                cout << "Monthly Interest Earned:\t\t\t\t $ " << setw(9) << right
                    << monthlyInterestEarned << endl;
                cout << "--------------------------------------------------------------------\n";
                cout << "Monthly Balance Total:\t\t\t\t\t $ " << setw(9) << right
                    << monthlyBalanceTotal << endl;
                cout << "--------------------------------------------------------------------\n";

            months++;
        }
   
        /* Display: Formatted  final output of the account balance sheet */
        cout << fixed << showpoint << setprecision(2);
        cout << "\n\n\t\tAshikaga Bank - Final Account Balance Sheet\n";
        cout << "--------------------------------------------------------------------\n";
        cout << "Account History: " << monthsPassed << " months\n";
        cout << "\nDeposits Total:\t\t\t\t\t $ " << setw(9) << right
            << depositsTotal << endl;
        cout << "Withdrawals Total:\t\t\t\t $ " << setw(9) << right
            << withdrawalsTotal << endl;
        cout << "Interest Earned Total:\t\t\t\t $ " << setw(9) << right
            << interestEarnedTotal << endl;
        cout << "--------------------------------------------------------------------\n";
        cout << "Account Balance Total:\t\t\t\t\t $ " << setw(9) << right
            << accountBalanceTotal << endl;
        cout << "--------------------------------------------------------------------\n";
    }

    pauseSystem();
    return 0;
}

Monday, December 19, 2016

Programming Challenge 5.15 - Payroll Report

/* Payroll Report - This program displays a weekly payroll report. A loop
   in the program asks the user for the employee number, gross pay, state
   tax and federal tax, and FICA withholdings. The loop will terminate when
   0 is entered, the program displays totals for gross pay, state tax,
   federal tax, FICA withholdings, and net pay.
  
   Input Validation: No negative numbers for any of the items entered are
   accepted. No values for state, federal or fica withholdings that are
   greater than the gross pay are accepted. If the sum of state tax +
   federal tax + FICA withholdings for any employee is greater than gross
   pay, an error message is printed, asking the user to reenter the data
   for the employee. */

#include "Utility.h"

int main()
{   
    /* Constant: QUIT */
    const int QUIT = 0;

    /* Variable: Employee number, Choice */
    int employeeNumber = 0,
        choice = 1;

    /* Variables: Gross pay, State tax, Federal tax, FICA withholdings, Total
       gross pay, Total state tax, Total federal tax, total FICA withholdings,
       Total Tax Amount, Net pay */
    double grossPay = 0,
           stateTax = 0,
           federalTax = 0,
           FICAWithholdings = 0,
           totalGrossPay = 0,
           totalStateTax = 0,
           totalFederalTax = 0,
           totalFICAWithholdings = 0,
           totalTax = 0,
           totalNetPay = 0;

    /* Display: Information */
    cout << "\t\tPAYROLL REPORT\n\n"
        << "This program allows you to generate an automated payroll\n"
        << "report for your employee(s). To proceed, you must provide\n"
        << "\n\t* The employee number (or I.D.)\n"
        << "\t* His or her gross pay\n"
        << "\t* The applicable state stax (effective tax rate!)\n"
        << "\t* The federal tax (effective tax rate!)\n"
        << "\t* The FICA withholdings.\n\n"
        << "Please proceed.\n";

    /* Do While loop: While the user does not enter 0 to quit, this loop
       will iterate */
    do
    {
        /* Nested While loop::Input::Input Validation: While any of the
           numbers the user enters is not -1, or choice is not quit, this
           loop will iterate */
        while (!(employeeNumber < 0 || grossPay < 0 || stateTax < 0 ||
            federalTax < 0 || FICAWithholdings < 0 || choice == QUIT))
        {
            /* Ask for the employee number, gross pay, state tax, federal
            tax and FICA withholdings */
            cout << "\nPlease enter the employee number (or I.D.): ";
            cin >> employeeNumber;

            /* Nested While loop::Input Validation: While employee number
               is lower than, or equal to 0, this loop will iterate */
            while (employeeNumber <= 0)
            {
                /* Display: An error message */
                cout << "An error occured: The number you entered was\n"
                    << "negative. All numbers must be positive.\n"
                    << "Employee Number: 42124\n";

                /* Ask again */
                cout << "Please enter the employee number (or I.D.): ";
                cin >> employeeNumber;
            }

            cout << "\nGross Pay:        $ ";
            cin >> grossPay;

            /* Nested While loop::Input Validation: While gross pay
            is lower than, or equal to 0, this loop will iterate */
            while (grossPay <= 0)
            {
                /* Display: An error message */
                cout << "\nAn error occured: The number you entered was\n"
                    << "negative. All numbers must be positive.\n"
                    << "Gross Pay: $27500.00\n";

                /* Ask again */
                cout << "Gross Pay:        $ ";
                cin >> grossPay;
            }

            cout << "State Tax:        % ";
            cin >> stateTax;

            /* Nested While loop::Input Validation: While state tax
               is lower than, or equal to 0, this loop will iterate */
            while (stateTax <= 0)
            {
                /* Display: An error message */
                cout << "\nAn error occured: The number you entered was either\n"
                    << "negative, or higher than the Marginal state tax rate\n"
                    << "of 4.00%.\n";

                /* Ask again */
                cout << "State Tax:        % ";
                cin >> stateTax;
            }

            cout << "Federal Tax:        % ";
            cin >> federalTax;

            /* Nested While loop::Input Validation: While state tax
               is lower than, or equal to 0, this loop will iterate */
            while (federalTax <= 0)
            {
                /* Display: An error message */
                cout << "\nAn error occured: The number you entered was either\n"
                    << "negative, or higher than the Marginal federal tax rate\n"
                    << "of 15.00%.\n";

                /* Ask again */
                cout << "Federal Tax:        % ";
                cin >> federalTax;
            }

            cout << "FICA Withholdings:    % ";
            cin >> FICAWithholdings;

            /* Nested While loop::Input Validation: While state tax
            is lower than, or equal to 0, this loop will iterate */
            while (FICAWithholdings <= 0)
            {
                /* Display: An error message */
                cout << "\nAn error occured: The number you entered was either\n"
                     << "negative, or higher than the Marginal FICA tax rate\n"
                     << "of 7.65%.\n";

                /* Ask again */
                cout << "FICA Withholdings:    % ";
                cin >> FICAWithholdings;
            }

            /* Calculations: State tax, Federal tax, FICA withholdings, Total
            tax amount, Total net pay */
            totalStateTax = (grossPay * stateTax) / 100;
            totalFederalTax = (grossPay * federalTax) / 100;
            totalFICAWithholdings = (grossPay * FICAWithholdings) / 100;
            totalTax = (totalStateTax + totalFederalTax + totalFICAWithholdings);
            totalNetPay = grossPay - totalTax;

            /* Calculation Validation::If statement: If, for whatever reason,
               the sum of state tax + federal tax + and FICA withholdings is
               greater than gross pay, an error message will be displayed */
            if (totalTax > grossPay)
            {
                /* Display: Error message */
                cout << "\nOh no, an error occured! The total tax can not be.\n"
                     << "greater than the gross pay. Please enter data for\n"
                     << "employee: " << employeeNumber << " once more.\n";
            }
            else
            {
                /* Display: The formatted report */
                cout << fixed << showpoint << setprecision(2);

                cout << "\nPayroll Report for Employee: " << employeeNumber << "\n";
                cout << "-----------------------------------------------------------\n";
                cout << "Gross Pay Amount:\t\t\t$ " << setw(8) << left << grossPay
                    << endl;
                cout << "-----------------------------------------------------------\n";
                cout << "Total State Tax:\t\t\t$ " << setw(8) << right << totalStateTax
                    << endl;
                cout << "Total Federal Tax:\t\t\t$ " << setw(8) << right << totalFederalTax
                    << endl;
                cout << "Total FICA Withholdings:\t\t$ " << setw(8) << right << totalFICAWithholdings
                    << endl;
                cout << "Total Tax Amount:\t\t\t$ " << setw(8) << right << totalTax
                    << endl;
                cout << "------------------------------------------------------------\n";
                cout << "Total Net Pay:\t\t\t\t$ " << setw(8) << left << totalNetPay
                    << "\n\n";

                /* Ask the user if he or she wishes to create another report */
                cout << "Enter 0 to Quit or 1 to create another report: ";
                cin >> choice;
            }
        }
    } while (choice != QUIT);
   
    pauseSystem();
    return 0;
}

Sunday, December 18, 2016

Programming Challenge 5.14 - Student Line Up

/* Student Line Up - A teacher has asked all her students to line up single
file according to their first name. For example, in one class Amy will be
at the front of the line and Yolanda will be at the end.

This program prompts the user to enter the number of students in the class,
then loops to read that many names. Once all the names have been read it
reports which student would be at the front of the line and which one would
be at the end of the line. It is assumed that no two students have the same
name.

Input Validation: No number less than 1 or greater than 25 for the number of
students are accepted. */

#include "Utility.h"

int main()
{
    /* Constants: Minimum number of student names, Maximum number of
       student names */
    const int STUDENT_NAMES_MIN = 1,
              STUDENT_NAMES_MAX = 25;

    /* Variables: First name, Last name, Name, First in line, Last in
       line */
    string firstName = " ",
           lastName = " ",
           studentName = " ",
           lineUpFirst = " ",
           lineUpLast = " ";

    /* Display: Information */
    cout << "\t\tStudent Line Up\n\n"
        << "Please enter the number of students in your class, followed\n"
        << "by their names. This program will then help you to determine,\n"
        << "which student has to stand at which position during role call.\n";

    /* Variables: Number of student names, Update (counter variable) */
    int numStudentNames = 1,
        update = 1;

    /* Input: Ask for the number of student names */
    cout << "\nEnter the number of names you wish to enter: ";
    cin >> numStudentNames;
    cin.ignore();

    /* While loop::Input Validation: As long as the number of student names
       is lower than STUDENT_NAMES_MIN (1), or greater than STUDENT_NAMES_MAX
       (25) this loop will iterate*/
    while (numStudentNames < STUDENT_NAMES_MIN ||
           numStudentNames > STUDENT_NAMES_MAX)
    {
        /* Display: Error message */
        cout << "It seems that you entered a value lower than 1, or\n"
             << "greater than 25. Please stay within the limit.\n";

        /* Ask for the number of student names again */
        cout << "Enter the number of names you wish to enter: ";
        cin >> numStudentNames;
        cin.ignore();
    }

        /* While loop: While update is smaller than or equal to the number
           of student names the user wishes to enter, this loop iterates */
    while (update <= numStudentNames)
    {
        /* Ask the user for the first and last names of her students */
        cout << "Enter first and last name: ";
        getline(cin, firstName), (cin, lastName);
        studentName = firstName, lastName;
       
        /* If Statement: If update is true, firstInLine and lastInLine
           get the variable name */
        if (update == 1)
        {
            lineUpFirst = studentName;
            lineUpLast = studentName;
         }

        /* Conditional Statement: Is the student name currently first in
           line smaller than the name the user entered? If so, first in
           line will get name */
        lineUpFirst = lineUpFirst < studentName ? lineUpFirst : studentName;
       
        /* Conditional Statement: Is the student name currently last in
           line greater than the name the user entered? If so, last in
           line will get name */
        lineUpLast = lineUpLast > studentName ? lineUpLast : studentName;
       
        update++;
    }

    /* Display: The names of the students who have to stand first and
       last in line */
    cout << "\nEvery morning, " << lineUpFirst << " stands first in line.\n";
    cout << "Every morning, " << lineUpLast << " stands last in line.\n";

    pauseSystem();
    return 0;
}

Friday, December 16, 2016

Programming Challenge 5.13 - The Greatest And The Least Of These

/* The Greatest And The Least Of These - This program uses a loop that lets
   the user enter a series of integers. To signal the end of the series, the
   user has to enter -99. After all numbers have been entered, the program
   displays the largest and the smallest numbers entered. */

#include "Utility.h"

int main()
{
    /* Constant: Quit input */
    const int QUIT_INPUT = -99;

    /* Variables: Count (counter variable), Numbers, Smallest Number,
       Greatest Number */
    int count = 1,
        number = 0,
        smallestNumber = 0,
        greatestNumber = 0;

    /* Display: Introduction */
    cout << "\t\tThe Greatest And The Least Of These\n\n"
         << "This program allows you to enter a series of numbers.\n"
         << "After you have finished your input and enter: -99\n"
         << "the smallest and greatest among all values will be\n"
         << "displayed.\n\n";

    /* For loop: As long as number is not equal to QUIT_INPUT (-99), this
       loop will iterate */
    for (count; number != QUIT_INPUT; count++)
    {
        /* Input: Ask the user for numbers */
        cout << "\nPlease enter a series of numbers: ";
        cin >> number;

        /* Validation::Input: If the number equals LOWEST_NUMBER (-99),
           the input will be ignored, and not be stored in the variable
           smallestNumber */
        if (number == -99)
        {
            continue;
        }

        /* Conditional Expressions: Is the number the user entered smaller
           than the number stored in smallest number? If so, the number is
           stored in the variable smallest number */
        smallestNumber = smallestNumber < number ? smallestNumber : number;
      
        /* Conditional Expressions: Is the number the user entered greater
           than the number stored in greatest number? If so, the number is
           stored in the variable greatest number */
        greatestNumber = greatestNumber > number ? greatestNumber : number;

        /* Display: The currently smallest and greatest number during
           input */
        cout << "\n " << smallestNumber << " is currently the least of these.\n";
        cout << " " << greatestNumber << " is currently the greatest of these.\n";

    }

    /* Display: The Greatest And The Least Of These Numbers */
    cout << "\nThe least of these numbers was: " << smallestNumber << endl;
    cout << "The greatest of these numbers was: " << greatestNumber << endl;

    pauseSystem();
    return 0;
}

Programming Challenge 5.12 - Celsius Fahrenheit Table

/* Celsius Fahrenheit Table - This program is an updated version of Programming
   Challenge 3.12. This version uses a loop to display a table of the Celsius
   temperatures 0-20, and their Fahrenheit equivalents. */

#include "Utility.h"

int main()
{
    /* Constants: Minimum temperature in Celsius,
       Maximum temperature in Celsius */
    const int CELSIUS_MIN = 0,
              CELSIUS_MAX = 20;

    /* Variables: Temperature in Celsius (counter variable, declared and
       initialized to CELSIUS_MIN), Temperature in Fahrenheit */
    double degreesCelsius = CELSIUS_MIN,
           degreesFahrenheit = 0;

    /* Display: General Information, Formatted table header */
    cout << "\t\tCelsius to Fahrenheit Converter\n\n"
         << "This program converts temperatures in Celsius (0 to 20)\n"
         << "and displays their Fahrenheit equivalent.\n";

    cout << "\nTemperature Celsius" << "\t\t\t\t" << "Temperature Fahrenheit\n"
         << "_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n";

    /* For loop: As long as the temperature in Celsius is lower than or
       equal to 20, this loop will iterate */
    for (degreesCelsius; degreesCelsius <= CELSIUS_MAX; degreesCelsius++)
    {
        /* Calculation: Conversion from Celsius to Fahrenheit */
        degreesFahrenheit = (degreesCelsius * 9 / 5) + 32;

        /* Display: Output */
        cout << "Deg. C.\t" << degreesCelsius << "\t\t\t\t\t"
             << "Deg. F.\t" << degreesFahrenheit << endl;
    }

    pauseSystem();
    return 0;
}