// Ch. 10 Demo #7
// Wyo C++
// October 24, 2001
// Purpose - uses a couple of struct variables and a function
#include <iostream.h>
struct Basket
{
int apples;
int grapes;
int candyBars;
double totalPrice;
char coupon;
};
struct Prices
{
double applePrice;
double grapePrice;
double candyBarPrice;
};
double computeTax(Basket myBasket);
int main()
{
Basket customer1;
Prices november;
double savings = 0.0;
november.applePrice = 0.60;
november.grapePrice = 1.50;
november.candyBarPrice = 0.85;
cout << "What letter is on your coupon ('X' if no coupon): ";
cin >> customer1.coupon;
cout << "Enter number of apples: ";
cin >> customer1.apples;
cout << "Enter number of lbs of grapes: ";
cin >> customer1.grapes;
cout << "Enter number of candy bars: ";
cin >> customer1.candyBars;
customer1.totalPrice = customer1.apples * november.applePrice +
customer1.grapes * november.grapePrice +
customer1.candyBars * november.candyBarPrice;
switch(customer1.coupon)
{
case 'A':
savings = 1.00;
break;
case 'B':
savings = 2.00;
break;
case 'C':
savings = 3.00;
break;
default:
savings = 0.00;
break;
}
cout << "Your total cost is " << customer1.totalPrice - savings + computeTax(customer1) << endl;
return 0;
}
double computeTax(Basket myBasket)
{
return 0.06 * myBasket.candyBars;
}