1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*************
Program: Asg10.cpp
Author: Alan P. Matie
Date: 01 Apr 2009
Description:
A program to compute and print your bill (with your name on it) if you order a pizza,
pop, and chicken wings. Sales tax is 10% (since pizza is classified as junk food!).
Output all input values and calculated values. You friend Tad gives you a 10% discount
on everything but the chicken wings.
New Concepts:
Challenges:
Introduce Return Value Functions
Last Modified: 07 Apr 2009
**************/
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
// Declare constants
const double DISCOUNT = 0.10;
const double SALESTAX = 0.10;
// Function Prototypes
double CalctotAmt(double pizza_cost, double pop_cost, double chicken_wing_cost);
double CalcdiscAmt(double pizza_cost, double pop_cost, double DISCOUNT);
double Calcsubtotal(double totAmt, double discAmt);
double CalctaxAmt(double subtotal, double SALESTAX);
double CalcdueAmt(double subtotal, double taxAmt);
int main()
{
// Declare variables below here
string name;
double pizza_cost, pop_cost, chicken_wing_cost, totAmt;
double discAmt, taxAmt, dueAmt, subtotal;
// Initialization Section for real number output. DO NOT MOVE!
cout <<setiosflags(ios::fixed | ios::showpoint);
cout <<setprecision(2);
// Begin your "main processing" below here
cout << "Please enter your name. Enter end to stop." <<endl;
cin >> name;
while (name != "end")
{
cout << "Please enter the cost of the pizza: $";
cin >> pizza_cost;
cout << "Please enter the cost of the pop: $";
cin >> pop_cost;
cout << "Please enter the cost of the chicken wings: $";
cin >> chicken_wing_cost;
cout << "Bill for: " <<name <<endl;
totAmt = CalctotAmt(pizza_cost, pop_cost, chicken_wing_cost);
discAmt = CalcdiscAmt(pizza_cost, pop_cost, DISCOUNT);
subtotal = Calcsubtotal(totAmt, discAmt);
taxAmt = CalctaxAmt(subtotal, SALESTAX);
dueAmt = CalcdueAmt(subtotal, taxAmt);
cout << "Total cost of food for: "<<name <<" $"<<totAmt <<endl;
cout << " Less discount on pizza and pop: $"<<discAmt <<endl;
cout << " Total less discount: $"<<subtotal <<endl;
cout << " Plus tax: $"<<taxAmt <<endl;
cout << "TOTAL DUE: $"<<dueAmt <<endl;
cout << "Please enter your name. Enter end to stop." <<endl;
cin >> name;
}
return 0;
}
// function definitions below here
double CalctotAmt(double pizza_cost, double pop_cost, double chicken_wing_cost)
{
double totAmt;
totAmt = (pizza_cost + pop_cost + chicken_wing_cost);
return totAmt;
}
double CalcdiscAmt(double pizza_cost, double pop_cost, double DISCOUNT)
{
double discAmt;
discAmt = ((pizza_cost + pop_cost) * DISCOUNT);
return discAmt;
}
double Calcsubtotal(double totAmt, double discAmt)
{
double subtotal;
subtotal = (totAmt - discAmt);
return subtotal;
}
double CalctaxAmt(double subtotal, double SALESTAX)
{
double taxAmt;
taxAmt = (subtotal * SALESTAX);
return taxAmt;
}
double CalcdueAmt(double subtotal, double taxAmt)
{
double dueAmt;
dueAmt = (subtotal + taxAmt);
return dueAmt;
}
| |