Monday, November 28, 2016

Geschafft in mehr als drei Sinnen

Es ist unglaublich, aber wahr - Kapitel 4 ist mit dem heutigen Tag: Geschichte!

Ich habe eine Menge gelernt, und zwar durch praktische Anwendung, wie wichtig es ist, die Warnungen und gut gemeinten Hinweise in den Kapiteln zu befolgen. Es vereinfacht das Leben um ein vielfaches, wenn es darum geht, Probleme zu lösen!

Kommentiere deinen Quellcode, achte auf die Struktur des Programms, setz dich hin und erstell einen Plan, wie du das Programm schreiben möchtest, und ähnliches mehr, fällt mir spontan ein was die gut gemeinten Hinweise anbelangt. Die Warnung: "Wenn du es nicht tust, wirst du es früher oder später bereuen!", würde ich so auch ohne weiteres unterschreiben. Nichts würde ich mehr hassen, als eines der gelösten Aufgaben zig mal neu schreiben zu müssen, nur weil es an irgendeiner Stelle, durch Faulheit, Unachtsamkeit und dergleichen mehr, meinerseits notwendig wäre! *würg*

Eine Sache habe ich jedenfalls mit einiger Deutlichkeit gelernt: Schreib deinen Code von Beginn an so, das er einfach erweiterbar ist. Die Lehre habe ich aus den letzten 3 Programming Challenges, die aus drei Teilen besteht, und das Programm jeweils um einige Funktionen ergänzt, besteht. Die Erweiterungen zu schreiben war eine Kleinigkeit für Programming Challenge 4.26, leider habe ich die in Challenge 4.27 nicht so ganz optimal gelöst. So, wie ich es mir vorgestellt habe, sollte der Teil des Quellcodes:

        /* Rev 2: Determine how many minutes a month has, based on the number of days in
        a month */
        if (monthName == "January" || monthName == "March" || monthName == "May" ||
            monthName == "July" || monthName == "August" || monthName == "October" ||
            monthName == "December")
        {
            hoursInMonth = 744;
            minutesInMonth = (hoursInMonth * 60);
        }
        else if (monthName == "April" || monthName == "June" || monthName == "September" ||
            monthName == "November")
        {
            hoursInMonth = 720;
            minutesInMonth = (hoursInMonth * 60);
        }
        else if (monthName == "February")
        {
            hoursInMonth = 672;
            minutesInMonth = (hoursInMonth * 60);
        }

Nur ein einziges mal im Programm stehen. Leider hat das aber nicht ganz geklappt. Außerhalb der switch case statements plaziert, und die Validierung innerhalb der 3 cases, so hätte es sein sollen. Doch plazierte ich es innerhalb, so kam ständig die Meldung, das bei der Eingabe ein Fehler aufgetreten sein müsse, die aber nur dann angezeigt werden sollte, wenn tatsächlich die Anzahl der Gesprächsminuten größer ist, als der jeweilige Monat an Minuten aufzuweisen hat. Dieses kleinen Schönheitsfehlers werde ich mich noch annehmen, bevor ich morgen dazu übergehe, und mich in Kapitel 5 verbeisse.

Ferner habe ich durch die Programming Challenges des aktuellen Kapitels gelernt, dass, was eigentlich ganz einfach aussieht, plötzlich recht kompliziert werden kann, wenn es an die Planung und Umsetzung geht. Oft waren es nur Kleinigkeiten, die mir aber die größten Probleme bereitet haben, wo ich wirklich mal laut AAAAAAAAAAAAAAAAAAAAAAH! geschrien, oder mir die Haare gerauft habe. Und das nicht nur einmal. Ich kann nur froh sein, das mein Haus recht gut isoliert ist, sodass es die Nachbarn nicht hören, sonst würden die mich schon längst für verrückt erklärt, und die Männer mit den weissen Liebesjacken gerufen. *gg* Jedenfalls, und zurück zum Punkt, lag es daran, dass ich manches falsch gedeutet habe ... und meinen Code fröhlich drauf los, auch so verfasst - und dann verworfen habe. So zum Beispiel Programming Challenge 4.24.

Bei dieser haben ich jedwede Planung fahren lassen, weil ja alles klar war. Kein Problem? Oh, doch! Weil ich so DUMM war, und die Angaben 00:00 für Beginn und 06:00 für den ersten Grenzwert hielt. Das es sich dabei möglicherweise nicht um 6h handelt, sondern um 00:00 Uhr bis 00:06 Uhr, kam mir nicht mal in den Sinn ... Bis ich das Programm so gut wie fertig hatte, da ging mir eine ganze Kerzenfabrik auf. Jedenfalls ließ sich letzendlich auch diese Challenge leicht lösen, nachdem ich noch mal drüber gegangen bin.

Ein anderer Fallstrick, den ich mir ständig selber stellte, ich weiß auch nicht wie das kommt, ist - ich beginne, eine wirklich recht einfache Sache gedanklich so sehr zu verkomplizieren, dass das eigentliche Problem größer erscheint, als es tatsächlich ist. Dem entsprechend nahm so mancher Schritt in einer der letzten 7 Challenges mehr Zeit in Anspruch, trotz Planung - oder vermutlich eben wegen dieser, als es hätte sein müssen.

Zusammengenommen waren dies alles sehr wertvolle Lektionen, die sich mir für Kapitel 5, und die mich dort erwartenden Challenges, gestehlt haben. Wenn ich meine Kristallkugel zu Rate ziehe, sehe ich allerdings auch schon voraus, das - wenn ich mal zum Ende von diesem großartigen Buch komme, ich mein eigenes Spiel vom Irrenhaus aus schreiben werde, weil ich total abgedreht bin. Will ich nicht hoffen, aber - wie heißt es beim Lotto? ALLES ist möglich.

In diesem Sinne wünsche ich Euch, die ihr diese Zeilen lest, eine erfolgreiche Woche, und denen, die ebenfalls C++ erlernen weiterhin viel Erfolg.

P.s. Bevor ich es vergesse, Casio, mein einzig liebster Lieblings-LKW-Fahrer, danke, für deine wertvolle Hilfe, beim lösen eines riesigen mathematischen Problems. Du weisst schon, welches ich meine. *zwinker*

P.p.s.: And thanks to one nice member who answered and helped me greatly by pointing me in the right direction, to solve a problem, that solved itself. If ever you read this, thanks, much appreciated.

Update

So nun habe ich auch Programming Challenge 4.27 so gelöst, wie es sein sollte, und den oben erwähnten redundanten Code raus bekommen ... Es war eigentlich nur eine Kleinigkeit, die nicht gepasst hat - obwohl der Rest, so wie er sein hätte sollen, funktionierte. Nun ist mein Glück perfekt, und ich werde mich wirklich auf das nächste Kapitel konzentrieren können, ohne dass mir das Problem nachhängt. :)

Programming Challenge 4.27 - Mobile Service Provider Mod Two

/* Mobile Service Provider Mod Two - A mobile phone service has three different
subscription packages for its customers:

* Package A:    For $39.99 per month 450 minutes are provided. Additional minutes are
$0.45 per minute.
* Package B: For $59.99 per month 900 minutes are provided. Additional minutes are
$0.40 per minute.
* Package C: For $69.99 per month unlimited minutes provided.

This program calculates a customer's monthly bill. It asks which package the
customer has purchased and how many minutes were used. It then displays the
total amount due.

----------------------------------------------------------------------------------------

Rev 1: This program displays how much money Package A customers would save, if they
purchased Package B or C, and how much money Package B customers would save, if they
purchased Package C. If there would be no savings, no message will be printed.

All calculations are based on the assumption, that a customer constantly makes calls
totaling to a lower amount of minutes than is included in their respective package,
to suggest to switch to a smaller package. This only applies to a switch from package
C to B, and, in case, from B to A if this promises savings.

----------------------------------------------------------------------------------------

Rev 2: Months with 30 days have 720 hours, and months with 31 days have 744 hours.
February, with 28 days, has 672 hours. The number of minutes can be calculated in a
month by multiplying its number of hours by 60.

This program enhances the input validation by asking the customer for the month (by
name), and validates that the number of minutes entered is not more than the maximum
for the entire month.

The following table shows months, number of days and number of hours:

Month            Days            Hours            Month            Days        Hours
January            31                744                July            31            744
February            28                672                August            31            744
March            31                744                September        30            720
April            30                720                October            31            744
May                31                744                November        30            720
June                30                720                December        31            744 */

#include "Utility.h"

int main()
{
    /* Rev 2: Constants for days in month */
    const int THIRTY_DAYS = 30,
        THIRTYONE_DAYS = 31,
        TWENTYEIGHT_DAYS = 28;

    /* Constants for provided minutes for package A and B

    Rev 1: minutes calc is added for calculation purposes and initialized with a
    value of 1440 minutes equaling 24 hrs. */
    const int MINUTES_PACKAGE_A = 450,
        MINUTES_PACKAGE_B = 900,
        MINUTES_CALC = 1440;

    /* Constants for base cost for packages A, B, and C */
    const double BASE_COST_PACKAGE_A = 39.99,
        BASE_COST_PACKAGE_B = 59.99,
        BASE_COST_PACKAGE_C = 69.99;

    /* Constants for additional cost per minute for package A and B */
    const double ADD_COST_PACKAGE_A = 0.45,
        ADD_COST_PACKAGE_B = 0.40;

    /* Constant for maximum number of minutes for input valdiation purposes */
    const int MAX_NUM_MINUTES = 59;

    /* Constants for subscription package menu choices */
    const int PACKAGE_A = 1,
        PACKAGE_B = 2,
        PACKAGE_C = 3,
        QUIT = 4;

    /* Hold menu choice for switch case statement */
    int choice = 0;

    /* Hold base cost and total cost for calculations
    Rev 1: savings, totalSavings, and premium savings */
    double totalCost = 0,
        savings = 0,
        totalSavings = 0,
        premiumSavings = 0;

    /* Hold number of hours, number of minutes, number of minutes extra, and
    total call length */
    int numHours = 0,
        numMinutes = 0,
        numMinutesExtra = 0,
        totalCallLength = 0;

    /* Rev 2: Hold month name */
    string monthName = " ";

    /* Rev 2: Hold month, hours in month, and minutes in month */
    int month = 0,
        hoursInMonth = 0,
        minutesInMonth = 0;

    /* Rev 2: Determine how many minutes a month has, based on the number of days in
    a month */
    if (monthName == "January" || monthName == "March" || monthName == "May" ||
        monthName == "July" || monthName == "August" || monthName == "October" ||
        monthName == "December")
    {
        hoursInMonth = 744;
        minutesInMonth = (hoursInMonth * 60);
    }
    else if (monthName == "April" || monthName == "June" || monthName == "September" ||
        monthName == "November")
    {
        hoursInMonth = 720;
        minutesInMonth = (hoursInMonth * 60);
    }
    else
    {
        hoursInMonth = 672;
        minutesInMonth = (hoursInMonth * 60);
    }

    /* Display menu */
    cout << "\t\tMobile Service Provider - Phone Bill Calculator\n\n"
        << "Welcome to your personal service area. Here you can calculate the\n"
        << "total cost of your telephone bill, based on your subscription\n"
        << "package. To do so, please select your package from the menu.\n\n"
        << "1. PACKAGE A\n"
        << "2. PACKAGE B\n"
        << "3. PACKAGE C\n"
        << "4. QUIT\n\n"
        << "Please enter your choice: ";
    cin >> choice;

    /* Switch case statements */
    switch (choice)
    {
    case 1:
        /* Display the customers menu choice and information about his or her
        subscription package */
        cout << "\nThe package you subscribed is: PACKAGE A.\n"
            << "This package costs: $" << BASE_COST_PACKAGE_A
            << " per month and includes " << MINUTES_PACKAGE_A << " minutes.\n"
            << "An additional cost of: $" << ADD_COST_PACKAGE_A << " per minute\n"
            << "will be charged if the total amount of minutes is greater than the\n"
            << "amount of minutes covered by your subscribed package.\n";

        /* Ask the customer for total length of phone calls in hours and minutes

        Rev 2: Ask the customer for the name of the month he or she is trying to query
        the cost for */
        cout << "Please enter the name of the month you wish us to process: ";
        cin >> monthName;
        cout << "Please enter the total amount of time in hours: ";
        cin >> numHours;
        cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
        cin >> numMinutes;

        /* Calculations - adding the number of hours and minutes to determine
        the total length of calls in minutes for further calculations */
        numHours *= 60;
        totalCallLength = (numHours + numMinutes);

        /* Input validation */
        if (numMinutes < 0 || numMinutes > 59)
        {
            cout << "\nYou entered an invalid amount of minutes. Please use 0 to 59 only.\n";
        }
        /* Rev 2: Input validation - Determine whether the minutes consumed are not greater
        than the total possible number of minutes in the month the consumer entered */
        else if (totalCallLength > minutesInMonth)
        {
            cout << "\nWe are very sorry for the inconvenience, but we are unable to process\n"
                << "your request. The most likely cause is that the number of minutes total\n"
                << "entered is greater than the total possible amount of minutes in the month\n"
                << "of: " << monthName << " that you provided. Please check your input, and\n"
                << "try again.\n\n";
        }
        /* Determine whether the total call length is above or below 450 minutes,
        calculate and display the total cost */
        else if (totalCallLength <= MINUTES_PACKAGE_A)
        {
            /* Display information and total cost of the phone bill */
            cout << "\nThe total length of your calls in " << monthName << " was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You didn't use up the total amount of minutes covered by your subscription\n"
                << "package of: " << MINUTES_PACKAGE_A << " minutes this month.\n"
                << "The total number of minutes of calls is: "
                << totalCallLength << " minutes.\n\n"
                << "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_A << endl;
        }
        else if (totalCallLength > MINUTES_PACKAGE_A)
        {
            /* Calculating the total call length and cost of calls plus extra */
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_A);
            totalCost = BASE_COST_PACKAGE_A + (numMinutesExtra * ADD_COST_PACKAGE_A);

            /* Display information about minutes used, extra minutes not included in
            the subscribed package, and total cost of the phone bill */
            cout << "\nThe total length of your calls in " << monthName << " was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "The total call length in minutes was: \t" << totalCallLength
                << " minutes.\n\n"
                << "You used up an additional amount of: " << numMinutesExtra
                << " minutes extra not covered by\n"
                << "your subscription package which only includes "
                << MINUTES_PACKAGE_A << " minutes.\n"
                << "Additional fees of $" << ADD_COST_PACKAGE_A
                << " per minute will be charged.\n\n"
                << "Base cost: $" << BASE_COST_PACKAGE_A
                << "\nPlus:       $ " << ADD_COST_PACKAGE_A << " extra.\n\n"
                << "The total cost of your phone bill is: \t$" << totalCost << endl;
        }

        /* Rev 1: Calculation of total savings (if any) a customer would save if he or she opted
        for PACKAGE B or PACKAGE C. If there are any savings to be made, additional
        output indicating the ideal package is displayed */
        if (totalCallLength > MINUTES_PACKAGE_B && totalCallLength < MINUTES_CALC)
        {
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);
            totalSavings = (totalCost - savings);

            cout << "\n\nIf you would opt for a subscription of PACKAGE B, you would be able\n"
                << "to make some real savings!\n\n"
                << "PACKAGE B would only cost: $" << BASE_COST_PACKAGE_B
                << " per month and includes " << MINUTES_PACKAGE_B << " minutes.\n"
                << "An additional cost of: $" << ADD_COST_PACKAGE_B << " per minute "
                << "would be charged if the total\n"
                << "amount of minutes is greater than the amount of minutes covered.\n\n"
                << "This month you would only have had to pay: $" << savings
                << " with PACKAGE B.\n"
                << "The total savings would have been as much as: $" << totalSavings << endl;
        }

        /* Rev 1: Calculating the savings and displaying the cost saved if a customer were
        to opt for a subscription of PACKAGE C instead of B if this is a cost saving option */
        if (totalCallLength > MINUTES_CALC && totalCallLength < minutesInMonth)
        {
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);
            totalSavings = (totalCost - savings);
            premiumSavings = (totalCost - BASE_COST_PACKAGE_C);

            cout << "\n\nDear customer! Judging by the total length of your "
                << "phone calls of: " << totalCallLength << " minutes,\n"
                << "we would like to suggest you switch to a subscription of PACKAGE C.\n"
                << "\nThis month you would have had to pay as much as as: $" << savings
                << " with PACKAGE B.\n"
                << "Which would have amounted to a saving of only: $" << totalSavings
                << "\n\nWith our premium package you would only have had to pay: $" << BASE_COST_PACKAGE_C
                << " only once!\n"

                << "The premium savings would amount to: $" << premiumSavings << "!\n\n";
        }
        break;

    case 2:
        /* Display the customers menu choice and information about his or her
        subscription package    */
        cout << "\nThe package you subscribed is: PACKAGE B.\n"
            << "This package costs: $ " << BASE_COST_PACKAGE_B
            << " per month and includes " << MINUTES_PACKAGE_B << " minutes.\n"
            << "An additional cost of: $" << ADD_COST_PACKAGE_B << " per minute\n"
            << "will be charged if the total amount of minutes is greater than the\n"
            << "amount of minutes covered by your subscribed package.\n";

        /* Ask the customer for total length of phone calls in hours and minutes

        Rev 2: Ask the customer for the name of the month he or she is trying to query
        the cost for */
        cout << "Please enter the name of the month you wish us to process: ";
        cin >> monthName;
        cout << "\nPlease enter the total amount of time in hours: ";
        cin >> numHours;
        cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
        cin >> numMinutes;

        /* Calculations */
        numHours *= 60;
        totalCallLength = (numHours + numMinutes);

        /* Input validation */
        if (numMinutes < 0 || numMinutes > 59)
        {
            cout << "You entered an invalid amount of minutes. Please use 0 to 59 only.\n";
        }

        /* Rev 2: Input validation - Determine whether the minutes consumed are not greater
        than the total possible number of minutes in the month the consumer entered */
        else if (totalCallLength > minutesInMonth)
        {
            cout << "\nWe are very sorry for the inconvenience, but we are unable to process\n"
                << "your request. The most likely cause is that the number of minutes total\n"
                << "entered is greater than the total possible amount of minutes in the month\n"
                << "of: " << monthName << " that you provided. Please check your input, and\n"
                << "try again.\n\n";
        }
        /* Determine whether the total call length is above or below 900 minutes, calculate
        and display the cost */
        else if (totalCallLength <= MINUTES_PACKAGE_B)
        {
            /* Display information and total cost of the phone bill */
            cout << "\nThe total length of your calls in " << monthName << " was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You didn't use up the total amount of minutes covered by your subscription\n"
                << "package of: " << MINUTES_PACKAGE_B << " minutes this month\n"
                << "The total number of minutes of calls is: " << totalCallLength << " minutes.\n\n"
                << "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_B << endl;
        }
        else if (totalCallLength > MINUTES_PACKAGE_B)
        {
            /* Calculating the total call length and cost of calls plus extra */
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            totalCost = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);

            /* Display information about minutes used, extra minutes not included in
            the subscribed package, and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You used up an additional amount of: " << numMinutesExtra
                << " minutes extra not covered by\n"
                << "your subscription package which only includes "
                << MINUTES_PACKAGE_B << " minutes.\n"
                << "Additional fees of $" << ADD_COST_PACKAGE_B
                << " per minute will be charged.\n\n"
                << "Base cost: $" << BASE_COST_PACKAGE_B
                << "\nPlus:       $ " << ADD_COST_PACKAGE_B << " extra.\n\n"
                << "The total cost of your phone bill is: \t$" << totalCost << endl;
        }

        /* Rev 1: Calculation of total savings (if any) a customer would save if he or she opted
        for PACKAGE A or PACKAGE C. If there are any savings to be made, additional
        output indicating the ideal package is displayed */
        if (totalCallLength <= MINUTES_PACKAGE_A)
        {
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_A;
            totalSavings = (BASE_COST_PACKAGE_B - savings);

            cout << "\n\nIf you would opt for a subscription of PACKAGE A, you would be able\n"
                << "to make some real savings!\n\n"
                << "PACKAGE A would only cost: $" << BASE_COST_PACKAGE_A
                << " per month and includes " << MINUTES_PACKAGE_A << " minutes.\n"
                << "An additional cost of: $" << ADD_COST_PACKAGE_A << " per minute "
                << "would be charged if the total\n"
                << "amount of minutes is greater than the amount of minutes covered.\n\n"
                << "This month you would only have had to pay: $" << savings
                << " with PACKAGE A.\n"
                << "The total savings would have been as much as: $" << totalSavings << endl;
        }

        /* Rev 1: Calculating the savings and displaying the cost saved if a customer were
        to opt for a subscription of PACKAGE C instead of B if this is a cost saving option */
        if (totalCallLength > MINUTES_CALC && totalCallLength < minutesInMonth)
        {
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);
            totalSavings = (totalCost - savings);
            premiumSavings = (totalCost - BASE_COST_PACKAGE_C);

            cout << "\n\nDear customer! Judging by the total length of your "
                << "phone calls of: " << totalCallLength << " minutes,\n"
                << "we would like to suggest you switch to a subscription of PACKAGE C.\n"
                << "\nThis month you would have had to pay as much as as: $" << savings
                << " with PACKAGE B.\n"
                << "Which would have amounted to a saving of only: $" << totalSavings
                << "\n\nWith our premium package you would only have had to pay: $" << BASE_COST_PACKAGE_C
                << " only once!\n"

                << "The premium savings would amount to: $" << premiumSavings << "!\n\n";
        }
        break;

    case 3:
        /* Display the customers menu choice and information about his or her
        subscription package    */
        cout << "\nThe package you subscribed is: PACKAGE C.\n"
            << "This package costs: $ " << BASE_COST_PACKAGE_C
            << " which includes an unlimited amount of minutes.\n"
            << "No additional costs will be charged.\n";

        /* Ask the customer for total length of phone calls in hours and minutes

        Rev 2: Ask the customer for the name of the month he or she is trying to query
        the cost for */
        cout << "Please enter the name of the month you wish us to process: ";
        cin >> monthName;
        cout << "\nPlease enter the total amount of time in hours: ";
        cin >> numHours;
        cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
        cin >> numMinutes;

        /* Calculations */
        numHours *= 60;
        totalCallLength = (numHours + numMinutes);

        /* Input validation */
        if (numMinutes < 0 || numMinutes > 59)
        {
            cout << "\nYou entered an invalid amount of minutes. Please use 0 to 59 only.\n";
        }
        /* Rev 2: Input validation - Determine whether the minutes consumed are not greater
        than the total possible number of minutes in the month the consumer entered */
        else if (totalCallLength > minutesInMonth)
        {
            cout << "\nWe are very sorry for the inconvenience, but we are unable to process\n"
                << "your request. The most likely cause is that the number of minutes total\n"
                << "entered is greater than the total possible amount of minutes in the month\n"
                << "of: " << monthName << " that you provided. Please check your input, and\n"
                << "try again.\n\n";
        }
        /* Determine whether the total call length and display the cost */
        else
        {
            /* Display information and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You have an unlimited amount of minutes covered by your subscription.\n"
                << "The total number of minutes of calls is: " << totalCallLength << " minutes.\n\n"
                << "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_C << endl;
        }

        if (totalCallLength < MINUTES_CALC || totalCallLength <= MINUTES_PACKAGE_B)
        {
            /* Rev 1: Calculating the savings and displaying the cost saved if a customer were
            to opt for a subscription of PACKAGE B if this is a cost saving option */
            savings = BASE_COST_PACKAGE_B;
            totalSavings = (BASE_COST_PACKAGE_C - savings);

            cout << "\n\nDear customer! Judging by the total length of your "
                << "phone calls of: " << totalCallLength << " minutes,\n"
                << "we would like to suggest you switch to a subscription of PACKAGE B.\n"
                << "\nThis month you would have had to pay as much as as: $" << savings
                << " with PACKAGE B.\n"
                << "Which would amount to a saving of: $" << totalSavings << endl;
        }
        break;

    case 4:
        /* Displaying a quit message */
        cout << "\nYou decided to quit the program. Thank you for your patronage!\n";
        break;

    default:
        /* If the menu choice is invalid and error message is displayed    */
        cout << "\nDear customer, you entered an invalid menu choice. Please choose 1 through 3, or\n"
            << "4 to quit this program. Thanks for your understanding.\n";
        break;
    }

    pauseSystem();
    return 0;
}

Programming Challenge 4.26 - Mobile Service Provider Mod

/* Mobile Service Provider Mod - A mobile phone service has three different subscription
   packages for its customers:
  
   * Package A:    For $39.99 per month 450 minutes are provided. Additional minutes are
                $0.45 per minute.
   * Package B: For $59.99 per month 900 minutes are provided. Additional minutes are
                $0.40 per minute.
   * Package C: For $69.99 per month unlimited minutes provided.

   This program calculates a customer's monthly bill. It asks which package the
   customer has purchased and how many minutes were used. It then displays the
   total amount due.

   ----------------------------------------------------------------------------------------

   Rev 1: This program displays how much money Package A customers would save, if they
   purchased Package B or C, and how much money Package B customers would save, if they
   purchased Package C. If there would be no savings, no message will be printed.
  
   All calculations are based on the assumption, that a customer constantly makes calls
   totaling to a lower amount of minutes than is included in their respective package,
   to suggest to switch to a smaller package. This only applies to a switch from package
   C to B, and, in case, from B to A if this promises savings. */

#include "Utility.h"

int main()
{
    /* Constants for provided minutes for package A and B

       Rev 1: minutes calc is added for calculation purposes and initialized with a
       value of 1440 minutes equaling 24 hrs. */
    const int MINUTES_PACKAGE_A = 450,
              MINUTES_PACKAGE_B = 900,
              MINUTES_CALC = 1440;

    /* Constants for base cost for packages A, B, and C */
    const double BASE_COST_PACKAGE_A = 39.99,
                 BASE_COST_PACKAGE_B = 59.99,
                 BASE_COST_PACKAGE_C = 69.99;

    /* Constants for additional cost per minute for package A and B */
    const double ADD_COST_PACKAGE_A = 0.45,
                 ADD_COST_PACKAGE_B = 0.40;

    /* Constant for maximum number of minutes for input valdiation purposes */
    const int MAX_NUM_MINUTES = 59;

    /* Constants for subscription package menu choices */
    const int PACKAGE_A = 1,
              PACKAGE_B = 2,
              PACKAGE_C = 3,
              QUIT = 4;

    /* Hold menu choice for switch case statement */
    int choice = 0;

    /* Hold base cost and total cost for calculations
    Rev 1: savings, totalSavings, and premium savings */
    double totalCost = 0,
        savings = 0,
        totalSavings = 0,
        premiumSavings = 0;

    /* Hold number of hours, number of minutes, number of minutes extra, and
       total call length */
    int numHours = 0,
        numMinutes = 0,
        numMinutesExtra = 0,
        totalCallLength = 0;

    /* Display menu */
    cout << "\t\tMobile Service Provider - Phone Bill Calculator\n\n"
        << "Welcome to your personal service area. Here you can calculate the\n"
        << "total cost of your telephone bill, based on your subscription\n"
        << "package. To do so, please select your package from the menu.\n\n"
        << "1. PACKAGE A\n"
        << "2. PACKAGE B\n"
        << "3. PACKAGE C\n"
        << "4. QUIT\n\n"
        << "Please enter your choice: ";
    cin >> choice;

    /* Switch case statements */
    switch (choice)
    {
    case 1:
        /* Display the customers menu choice and information about his or her
           subscription package */
        cout << "\nThe package you subscribed is: PACKAGE A.\n"
            << "This package costs: $" << BASE_COST_PACKAGE_A
            << " per month and includes " << MINUTES_PACKAGE_A << " minutes.\n"
            << "An additional cost of: $" << ADD_COST_PACKAGE_A << " per minute\n"
            << "will be charged if the total amount of minutes is greater than the\n"
            << "amount of minutes covered by your subscribed package.\n";

        /* Ask the customer for total length of phone calls in hours and minutes */
        cout << "\nPlease enter the total amount of time in hours: ";
        cin >> numHours;
        cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
        cin >> numMinutes;

        /* Calculations - adding the number of hours and minutes to determine
           the total length of calls in minutes for further calculations */
        numHours *= 60;
        totalCallLength = (numHours + numMinutes);

        /* Input validation */
        if (numMinutes < 0 || numMinutes > 59)
        {
            cout << "\nYou entered an invalid amount of minutes. Please use 0 to 59 only.\n";
        }
        /* Determine whether the total call length is above or below 450 minutes,
           calculate and display the total cost */
        else if (totalCallLength <= MINUTES_PACKAGE_A)
        {
            /* Display information and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You didn't use up the total amount of minutes covered by your subscription\n"
                << "package of: " << MINUTES_PACKAGE_A << " minutes this month.\n"
                << "The total number of minutes of calls is: "
                << totalCallLength << " minutes.\n\n"
                << "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_A << endl;
        }
        else if (totalCallLength > MINUTES_PACKAGE_A)
        {
            /* Calculating the total call length and cost of calls plus extra */
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_A);
            totalCost = BASE_COST_PACKAGE_A + (numMinutesExtra * ADD_COST_PACKAGE_A);

            /* Display information about minutes used, extra minutes not included in
            the subscribed package, and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "The total call length in minutes was: \t" << totalCallLength
                << " minutes.\n\n"
                << "You used up an additional amount of: " << numMinutesExtra
                << " minutes extra not covered by\n"
                << "your subscription package which only includes "
                << MINUTES_PACKAGE_A << " minutes.\n"
                << "Additional fees of $" << ADD_COST_PACKAGE_A
                << " per minute will be charged.\n\n"
                << "Base cost: $" << BASE_COST_PACKAGE_A
                << "\nPlus:       $ " << ADD_COST_PACKAGE_A << " extra.\n\n"
                << "The total cost of your phone bill is: \t$" << totalCost << endl;
        }

        /* Rev 1: Calculation of total savings (if any) a customer would save if he or she opted
        for PACKAGE B or PACKAGE C. If there are any savings to be made, additional
        output indicating the ideal package is displayed */
        if (totalCallLength >= MINUTES_PACKAGE_B && totalCallLength < MINUTES_CALC)
        {
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);
            totalSavings = (totalCost - savings);

            cout << "\n\nIf you would opt for a subscription of PACKAGE B, you would be able\n"
                << "to make some real savings!\n\n"
                << "PACKAGE B would only cost: $" << BASE_COST_PACKAGE_B
                << " per month and includes " << MINUTES_PACKAGE_B << " minutes.\n"
                << "An additional cost of: $" << ADD_COST_PACKAGE_B << " per minute "
                << "would be charged if the total\n"
                << "amount of minutes is greater than the amount of minutes covered.\n\n"
                << "This month you would only have had to pay: $" << savings
                << " with PACKAGE B.\n"
                << "The total savings would have been as much as: $" << totalSavings << endl;
        }

        /* Rev 1: Calculating the savings and displaying the cost saved if a customer were
        to opt for a subscription of PACKAGE C instead of B if this is a cost saving option */
        else if (totalCallLength > MINUTES_CALC)
        {
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);
            totalSavings = (totalCost - savings);
            premiumSavings = (totalCost - BASE_COST_PACKAGE_C);

            cout << "\n\nDear customer! Judging by the total length of your "
                << "phone calls of: " << totalCallLength << " minutes,\n"
                << "we would like to suggest you switch to a subscription of PACKAGE C.\n"
                << "\nThis month you would have had to pay as much as as: $" << savings
                << " with PACKAGE B.\n"
                << "Which would have amounted to a saving of only: $" << totalSavings
                << "\n\nWith our premium package you would only have had to pay: $" << BASE_COST_PACKAGE_C
                << " only once!\n"

                << "The premium savings would amount to: $" << premiumSavings << "!\n\n";
        }

        break;

    case 2:
        /* Display the customers menu choice and information about his or her
           subscription package    */
        cout << "\nThe package you subscribed is: PACKAGE B.\n"
             << "This package costs: $ " << BASE_COST_PACKAGE_B
             << " per month and includes " << MINUTES_PACKAGE_B << " minutes.\n"
             << "An additional cost of: $" << ADD_COST_PACKAGE_B << " per minute\n"
             << "will be charged if the total amount of minutes is greater than the\n"
             << "amount of minutes covered by your subscribed package.\n";

        /* Ask the customer for total length of phone calls in hours and minutes */
        cout << "\nPlease enter the total amount of time in hours: ";
        cin >> numHours;
        cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
        cin >> numMinutes;

        /* Calculations */
        numHours *= 60;
        totalCallLength = (numHours + numMinutes);

        /* Input validation */
        if (numMinutes < 0 || numMinutes > 59)
        {
            cout << "You entered an invalid amount of minutes. Please use 0 to 59 only.\n";
        }
        /* Determine whether the total call length is above or below 900 minutes, calculate
           and display the cost */
        else if (totalCallLength <= MINUTES_PACKAGE_B)
        {
            /* Display information and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You didn't use up the total amount of minutes covered by your subscription\n"
                << "package of: " << MINUTES_PACKAGE_B << " minutes this month\n"
                << "The total number of minutes of calls is: " << totalCallLength << " minutes.\n\n"
                << "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_B << endl;
        }
        else if (totalCallLength > MINUTES_PACKAGE_B)
        {
            /* Calculating the total call length and cost of calls plus extra */
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            totalCost = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);

            /* Display information about minutes used, extra minutes not included in
            the subscribed package, and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You used up an additional amount of: " << numMinutesExtra
                << " minutes extra not covered by\n"
                << "your subscription package which only includes "
                << MINUTES_PACKAGE_B << " minutes.\n"
                << "Additional fees of $" << ADD_COST_PACKAGE_B
                << " per minute will be charged.\n\n"
                << "Base cost: $" << BASE_COST_PACKAGE_B
                << "\nPlus:       $ " << ADD_COST_PACKAGE_B << " extra.\n\n"
                << "The total cost of your phone bill is: \t$" << totalCost << endl;
        }

        /* Rev 1: Calculation of total savings (if any) a customer would save if he or she opted
        for PACKAGE A or PACKAGE C. If there are any savings to be made, additional
        output indicating the ideal package is displayed */
        if (totalCallLength <= MINUTES_PACKAGE_A)
        {
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_A;
            totalSavings = (BASE_COST_PACKAGE_B - savings);

            cout << "\n\nIf you would opt for a subscription of PACKAGE A, you would be able\n"
                << "to make some real savings!\n\n"
                << "PACKAGE A would only cost: $" << BASE_COST_PACKAGE_A
                << " per month and includes " << MINUTES_PACKAGE_A << " minutes.\n"
                << "An additional cost of: $" << ADD_COST_PACKAGE_A << " per minute "
                << "would be charged if the total\n"
                << "amount of minutes is greater than the amount of minutes covered.\n\n"
                << "This month you would only have had to pay: $" << savings
                << " with PACKAGE A.\n"
                << "The total savings would have been as much as: $" << totalSavings << endl;
        }

        /* Rev 1: Calculating the savings and displaying the cost saved if a customer were
        to opt for a subscription of PACKAGE C instead of B if this is a cost saving option */
        else if (totalCallLength >= MINUTES_CALC)
        {

            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);
            totalSavings = (totalCost - savings);
            premiumSavings = (totalCost - BASE_COST_PACKAGE_C);

            cout << "\n\nDear customer! Judging by the total length of your "
                << "phone calls of: " << totalCallLength << " minutes,\n"
                << "we would like to suggest you switch to a subscription of PACKAGE C.\n"
                << "\nThis month you would have had to pay as much as as: $" << savings
                << " with PACKAGE B.\n"
                << "Which would have amounted to a saving of only: $" << totalSavings
                << "\n\nWith our premium package you would only have had to pay: $" << BASE_COST_PACKAGE_C
                << " only once!\n"

                << "The premium savings would amount to: $" << premiumSavings << "!\n\n";
        }
        break;
       
    case 3:
        /* Display the customers menu choice and information about his or her
        subscription package    */
        cout << "\nThe package you subscribed is: PACKAGE C.\n"
             << "This package costs: $ " << BASE_COST_PACKAGE_C
             << " which includes an unlimited amount of minutes.\n"
             << "No additional costs will be charged.\n";

        /* Ask the customer for total length of phone calls in hours and minutes */
        cout << "\nPlease enter the total amount of time in hours: ";
        cin >> numHours;
        cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
        cin >> numMinutes;

        /* Calculations */
        numHours *= 60;
        totalCallLength = (numHours + numMinutes);

        /* Input validation */
        if (numMinutes < 0 || numMinutes > 59)
        {
            cout << "\nYou entered an invalid amount of minutes. Please use 0 to 59 only.\n";
        }
        /* Determine whether the total call length and display the cost */
        else
        {
            /* Display information and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You have an unlimited amount of minutes covered by your subscription.\n"
                << "The total number of minutes of calls is: " << totalCallLength << " minutes.\n\n"
                << "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_C << endl;
        }

        if (totalCallLength < MINUTES_CALC || totalCallLength <= MINUTES_PACKAGE_B)
        {
            /* Rev 1: Calculating the savings and displaying the cost saved if a customer were
            to opt for a subscription of PACKAGE B if this is a cost saving option */
            savings = BASE_COST_PACKAGE_B;
            totalSavings = (BASE_COST_PACKAGE_C - savings);

            cout << "\n\nDear customer! Judging by the total length of your "
                << "phone calls of: " << totalCallLength << " minutes,\n"
                << "we would like to suggest you switch to a subscription of PACKAGE B.\n"
                << "\nThis month you would have had to pay as much as as: $" << savings
                << " with PACKAGE B.\n"
                << "Which would amount to a saving of: $" << totalSavings << endl;
        }
        break;

    case 4:
        /* Displaying a quit message */
        cout << "\nYou decided to quit the program. Thank you for your patronage!\n";
        break;

    default:
        /* If the menu choice is invalid and error message is displayed    */
        cout << "\nDear customer, you entered an invalid menu choice. Please choose 1 through 3, or\n"
             << "4 to quit this program. Thanks for your understanding.\n";
        break;
    }

    pauseSystem();
    return 0;
}

Sunday, November 27, 2016

Programming Challenge 4.25 - Mobile Service Provider

/* Mobile Service Provider - A mobile phone service has three different subscription
   packages for its customers:
  
   * Package A:    For $39.99 per month 450 minutes are provided. Additional minutes are
                $0.45 per minute.
   * Package B: For $59.99 per month 900 minutes are provided. Additional minutes are
                $0.40 per minute.
   * Package C: For $69.99 per month unlimited minutes provided.

   This program calculates a customer's monthly bill. It asks which package the
   customer has purchased and how many minutes were used. It then displays the
   total amount due. */

#include "Utility.h"

int main()
{
    /* Constants for provided minutes for package A and B */
    const int MINUTES_PACKAGE_A = 450,
              MINUTES_PACKAGE_B = 900;

    /* Constants for base cost for packages A, B, and C */
    const double BASE_COST_PACKAGE_A = 39.99,
                 BASE_COST_PACKAGE_B = 59.99,
                 BASE_COST_PACKAGE_C = 69.99;

    /* Constants for additional cost per minute for package A and B */
    const double ADD_COST_PACKAGE_A = 0.45,
                 ADD_COST_PACKAGE_B = 0.40;

    /* Constant for maximum number of minutes for input valdiation purposes */
    const int MAX_NUM_MINUTES = 59;

    /* Constants for subscription package menu choices */
    const int PACKAGE_A = 1,
              PACKAGE_B = 2,
              PACKAGE_C = 3,
              QUIT = 4;

    /* Hold menu choice for switch case statement */
    int choice = 0;

    /* Hold base cost and total cost for calculations */
    double totalCost = 0;

    /* Hold number of hours, number of minutes, number of minutes extra, and
       total call length */
    int numHours = 0,
        numMinutes = 0,
        numMinutesExtra = 0,
        totalCallLength = 0;

    /* Display menu */
    cout << "\t\tMobile Service Provider - Phone Bill Calculator\n\n"
         << "Welcome to your personal service area. Here you can calculate the\n"
         << "total cost of your telephone bill, based on your subscription\n"
         << "package. To do so, please select your package from the menu.\n\n"
         << "1. PACKAGE A\n"
         << "2. PACKAGE B\n"
         << "3. PACKAGE C\n"
         << "4. QUIT\n\n"
         << "Please enter your choice: ";
    cin >> choice;

    /* Switch case statements */
    switch (choice)
    {
    case 1:
        /* Display the customers menu choice and information about his or her
           subscription package */
        cout << "\nThe package you subscribed is: PACKAGE A.\n"
            << "This package costs: $" << BASE_COST_PACKAGE_A
            << " per month and includes " << MINUTES_PACKAGE_A << " minutes.\n"
            << "An additional cost of: $" << ADD_COST_PACKAGE_A << " per minute\n"
            << "will be charged if the total amount of minutes is greater than the\n"
            << "amount of minutes covered by your subscribed package.\n";

        /* Ask the customer for total length of phone calls in hours and minutes */
        cout << "\nPlease enter the total amount of time in hours: ";
        cin >> numHours;
        cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
        cin >> numMinutes;

        /* Calculations - adding the number of hours and minutes to determine
           the total length of calls in minutes for further calculations */
        numHours *= 60;
        totalCallLength = (numHours + numMinutes);

        /* Input validation */
        if (numMinutes < 0 || numMinutes > 59)
        {
            cout << "\nYou entered an invalid amount of minutes. Please use 0 to 59 only.\n";
        }
        /* Determine whether the total call length is above or below 450 minutes,
           calculate and display the total cost */
        else if (totalCallLength <= MINUTES_PACKAGE_A)
        {
            /* Display information and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You didn't use up the total amount of minutes covered by your subscription\n"
                << "package of: " << MINUTES_PACKAGE_A << " minutes this month.\n"
                << "The total number of minutes of calls is: "
                << totalCallLength << " minutes.\n\n"
                << "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_A << endl;
        }
        else if (totalCallLength > MINUTES_PACKAGE_A)
        {
            /* Calculating the total call length and cost of calls plus extra */
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_A);
            totalCost = BASE_COST_PACKAGE_A + (numMinutesExtra * ADD_COST_PACKAGE_A);

            /* Display information about minutes used, extra minutes not included in
            the subscribed package, and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You used up an additional amount of " << numMinutesExtra
                << " minutes extra not covered by\n"
                << "your subscription package which only includes "
                << MINUTES_PACKAGE_A << " minutes.\n"
                << "Additional fees of: $" << ADD_COST_PACKAGE_A
                << " per minute will be charged.\n\n"
                << "Base cost: $" << BASE_COST_PACKAGE_A
                << "\nPlus:       $ " << ADD_COST_PACKAGE_A << " extra.\n\n"
                << "The total cost of your phone bill is: \t$" << totalCost << endl;
        }
        break;

    case 2:
        /* Display the customers menu choice and information about his or her
           subscription package    */
        cout << "\nThe package you subscribed is: PACKAGE B.\n"
             << "This package costs: $ " << BASE_COST_PACKAGE_B
             << " per month and includes " << MINUTES_PACKAGE_B << " minutes.\n"
             << "An additional cost of: $" << ADD_COST_PACKAGE_B << " per minute\n"
             << "will be charged if the total amount of minutes is greater than the\n"
             << "amount of minutes covered by your subscribed package.\n";

        /* Ask the customer for total length of phone calls in hours and minutes */
        cout << "\nPlease enter the total amount of time in hours: ";
        cin >> numHours;
        cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
        cin >> numMinutes;

        /* Calculations */
        numHours *= 60;
        totalCallLength = (numHours + numMinutes);

        /* Input validation */
        if (numMinutes < 0 || numMinutes > 59)
        {
            cout << "You entered an invalid amount of minutes. Please use 0 to 59 only.\n";
        }
        /* Determine whether the total call length is above or below 900 minutes, calculate
           and display the cost */
        else if (totalCallLength <= MINUTES_PACKAGE_B)
        {
            /* Display information and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You didn't use up the total amount of minutes covered by your subscription\n"
                << "package of: " << MINUTES_PACKAGE_B << " minutes this month\n"
                << "The total number of minutes of calls is: " << totalCallLength << " minutes.\n\n"
                << "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_B << endl;
        }
        else if (totalCallLength > MINUTES_PACKAGE_B)
        {
            /* Calculating the total call length and cost of calls plus extra */
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            totalCost = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);

            /* Display information about minutes used, extra minutes not included in
            the subscribed package, and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You used up an additional amount of: " << numMinutesExtra
                << " minutes extra not covered by\n"
                << "your subscription package which only includes "
                << MINUTES_PACKAGE_B << " minutes.\n"
                << "Additional fees of $" << ADD_COST_PACKAGE_B
                << " per minute will be charged.\n\n"
                << "Base cost: $" << BASE_COST_PACKAGE_B
                << "\nPlus:       $ " << ADD_COST_PACKAGE_B << " extra.\n\n"
                << "The total cost of your phone bill is: \t$" << totalCost << endl;
        }
        break;
       
    case 3:
        /* Display the customers menu choice and information about his or her
        subscription package    */
        cout << "\nThe package you subscribed is: PACKAGE C.\n"
            << "This package costs: $ " << BASE_COST_PACKAGE_C
            << " which includes an unlimited amount of minutes.\n"
            << "No additional costs will be charged.\n";

        /* Ask the customer for total length of phone calls in hours and minutes */
        cout << "\nPlease enter the total amount of time in hours: ";
        cin >> numHours;
        cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
        cin >> numMinutes;

        /* Calculations */
        numHours *= 60;
        totalCallLength = (numHours + numMinutes);

        /* Input validation */
        if (numMinutes < 0 || numMinutes > 59)
        {
            cout << "\nYou entered an invalid amount of minutes. Please use 0 to 59 only.\n";
        }
        /* Determine whether the total call length and display the cost */
        else
        {
            /* Display information and total cost of the phone bill */
            cout << "\nThe total length of your calls this month was: "
                << (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
                << "You have an unlimited amount of minutes covered by your subscription.\n"
                << "The total number of minutes of calls is: " << totalCallLength << " minutes.\n\n"
                << "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_C << endl;
        }
        break;

    case 4:
        /* Displaying a quit message */
        cout << "\nYou decided to quit the program. Thank you for your patronage!\n";
        break;

    default:
        /* If the menu choice is invalid and error message is displayed    */
        cout << "\nDear customer, you entered an invalid menu choice. Please choose 1 through 3, or\n"
             << "4 to quit this program. Thanks for your understanding.\n";
        break;
    }

    pauseSystem();
    return 0;
}