Tuesday, November 22, 2016

Programming Challenge 4.13 - Book Club Awarded

/* Book Club Awarded - Serendipity Booksellers has a book club that awards points
   to its customers based on the number of books purchased each month. The points
   are awarded as follows:
 
   * If a customer purchases 0 books, he or she earns 0 points
   * If a customer purchases 1 book, he or she earns 5 points
   * If a customer purchases 2 books, he or she earns 15 points
   * If a customer purchases 4 or more books, he or she earns 60 points

   This program asks the user to enter the number of books that he or she has
   purchased this month and then displays the number of points awarded. */

#include "Utility.h"

int main()
{
    /* Constants for awarded points */
    const int ZERO_POINTS = 0,
              FIVE_POINTS = 5,
              FIFTEEN_POINTS = 15,
              THIRTY_POINTS = 30,
              SIXTY_POINTS = 60;

    /* Hold number of books */
    int numBooks;

    /* Ask the user how many books he or she bought this month */
    cout << "\t\tWelcome to Serendipity Book Club\n\n"
        << "How many books have you purchased this month? ";
    cin >> numBooks;

    if (numBooks == 0)
    {
        cout << "You didn't purchase any books this month.\n"
            << "You are awarded " << ZERO_POINTS << " points.\n";
    }
    else if (numBooks == 1)
    {
        cout << "You purchased " << numBooks << " books this month.\n"
            << "You are awarded: " << FIVE_POINTS << " points.\n";
    }
    else if (numBooks == 2)
    {
        cout << "You purchased " << numBooks << " books this month.\n"
            << "You are awarded: " << FIFTEEN_POINTS << " points.\n";
    }
    else if (numBooks == 3)
    {
        cout << "You purchased " << numBooks << " books this month.\n"
            << "You are awarded: " << THIRTY_POINTS << " points.\n";
    }
    else
    {
        cout << "You purchased " << numBooks << " books this month!\n"
            << "You receive our special award: " << SIXTY_POINTS << " points.\n";
    }

    pauseSystem();
    return 0;
}

No comments:

Post a Comment