// tgiddens_assig2.cpp
// Assignment 2 Decision Making
// Timothy Giddens
// IS 2043.002 Spring 07
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
// individual book price constants
const double PR_LASSI = 7.25,
PR_ROBIN = 9.75,
PR_OLIVE = 6.75,
PR_LITTL = 5.50,
DISC_5 = 0.05, // %5 discount for locals
DISC_10 = 0.10; // %10 discount for locals
// integer counter variables
int count_customer_no = 0,
count_total_books = 0,
count_lassie_bk = 0,
count_robin_bk = 0,
count_olive_bk = 0,
count_littl_bk = 0;
// Display menu selector
int selection; // user enters 1 or 2
// various charges variables
double sales_las = 0.00,
sales_rob = 0.00,
sales_oli = 0.00,
sales_lit = 0.00,
grand_total_sales = 0.00,
total_sales = 0.00,
tot_chg_pre_disc = 0.00,
final_charge = 0.00,
discount = final_charge - total_sales,
shipping = 0.00; //shipping charge for internet users
// selector variables
char response = ' ', // main menu selector input; user enters 'Y'
book_selection = ' ', // book menu switch selector input; user enters 'Y'
book_response = ' ',
select_las = '1',
select_rob = '2',
select_oli = '3',
select_lit = '4',
customer_type;
// set output display format
cout << setprecision(2)
<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint);
do
{
// display welcome menu & recv input for menu choice (1 or 2)
cout << "Welcome to Johnson's Bookstore" << endl;
cout << "==============================" << endl;
cout << "1 - Process Transaction" << endl;
cout << "2 - Display Overall Report" << endl << endl;
cout << "Please enter your selection: ";
cin >> selection;
cout << endl;
//decision making process for menu choice and sub menu transactions
if(selection == 1)
{
// menu choice 1 - process transaction selected
count_customer_no++; // customer_no accum
cout << "Customer #: "<< count_customer_no << endl; // display Customer number/transaction
cout << endl;
cout << "Please enter customer type (I-Internet, L-Local) : "; // Select Customer Type I or L
cin >> customer_type;
cout << endl;
switch(customer_type) // decision making process for customer type (discout or shipping charges)
{
case 'i':
case 'I':
/* internet customer shipping calculations BEGIN */
if(total_sales < 50.00)
{
shipping = 3.00; // declaration of shipping charge for this sale amount
final_charge = total_sales + shipping; // final charge for internet customer
}
else
shipping = 0.00;
break;
/* internet customer shipping calculations END */
case 'L':
case 'l':
/* local customer discount calculation BEGIN */
if(total_sales > 60.00)
{
final_charge = (total_sales - (total_sales * DISC_10));
}
else if((total_sales > 30.00) && (total_sales < 59.99))
{
final_charge = (total_sales - (total_sales * DISC_5));
}
break;
/* local customer discount calculation END */
default:
cout << endl;
cout << "Incorrect Customer Type! Try Again!" << endl;
break;
}
do // loop for displaying books
{
// display list of books
cout << "Available Titles" << endl;
cout << "================" << endl;
cout << "1 - Lassie ($7.25)" << endl;
cout << "2 - Robinson Crusoe ($9.75)" << endl;
cout << "3 - Oliver Twist ($6.75)" << endl;
cout << "4 - Little Women ($5.50)" << endl;
cout << endl;
cout << "Please enter your selection: ";
cin.get();
book_selection = cin.get();
switch(book_selection)
{
case '1':
cout << "Enter the number of Lassie books sold: ";
cin >> count_lassie_bk;
break;
case '2':
cout << "Enter the number of Robinson Crusoe books sold: ";
cin >> count_robin_bk;
break;
case '3':
cout << "Enter the number of Oliver Twist books sold: ";
cin >> count_olive_bk;
break;
case '4':
cout << "Enter the number of Little Women books sold: ";
cin >> count_littl_bk;
break;
default:
cout << "Incorrect selection! Try Again." << endl;
break;
}
// Prompt user to continue with another book
cout << "Do you want to continue with another book? (Y to continue or S to stop): ";
cin >> book_response;
cout << endl;
}
while(book_response == 'Y' || book_response == 'y');
// perform calculations
sales_las = (count_lassie_bk * PR_LASSI);
sales_rob = (count_robin_bk * PR_ROBIN);
sales_oli = (count_olive_bk * PR_OLIVE);
sales_lit = (count_littl_bk * PR_LITTL);
count_total_books = (count_lassie_bk + count_robin_bk + count_olive_bk + count_littl_bk);
total_sales = (sales_las + sales_oli + sales_rob + sales_lit);
grand_total_sales += total_sales;
// display current sale report
if(book_response == 's' || book_response == 'S')
{
cout << "The customer has purchased:" << endl;
cout << "(" << count_lassie_bk << ")" << " Lassie" << endl;
cout << "(" << count_robin_bk << ")" << " Robinson Crusoe" << endl;
cout << "(" << count_olive_bk << ")" << " Oliver Twist" << endl;
cout << "(" << count_littl_bk << ")" << " Little Women" << endl << endl;
cout << "The sale is: $" << total_sales << endl;
cout << "The shipping cost is: $" << shipping << endl;
cout << "The discount given is: $" << discount << endl;
cout << "The final charge is: $" << final_charge << endl << endl;
}
// Prompt user to continue with another transaction
cout << "Do you want to continue with the program? (Y to continue):";
cin >> response;
cout << endl;
}
else
if(selection == 2)
{
cout << "Final Report:" << endl;
cout << endl;
cout << " Title Total Sales" << endl;
cout << "===============================" << endl;
cout << " Lassie" << setw(7) << count_lassie_bk << setw(7) << sales_las << endl;
cout << " Robinson Crusoe" << setw(7) << count_robin_bk << setw(7) << sales_rob << endl;
cout << " Oliver Twist" << setw(7) << count_olive_bk << setw(7) << sales_oli << endl;
cout << " Little Women" << setw(7) << count_littl_bk << setw(7) << sales_lit << endl;
cout << "===============================" << endl;
cout << " Grand Total" << setw(7) << count_total_books << setw(7) << grand_total_sales << endl;
}
else
cout << "You Entered an Incorrect Response. Try Again!" << endl;
}
while(response == 'Y' || response == 'y');
return 0;
}