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
|
#include <iostream>
#include <iomanip>
using namespace std;
// this is okay
double calcDiscount(int quantity, double costEach, double discountPerCent, int orderMoreThan);
int main()
{
// this is in the wrong place - it's a function prototype, not a variable
double calcDiscount(int quantity, double costEach, double discountPerCent, int orderMoreThan);
// instead of using individual variables, you can use an array for each of these
// int quantity[3];
// then in your program, you can refer each index as a meal
// so 0 would be breakfast, 1 would be lunch, and 2 would be dinner
// then do the same for cost, and discount, and discount cap
// you can then use a loop to call your calcDiscount function
// using the index of the arrays as the formal parameters
// nevermind -- too confusing, I'm sure
// you also have your costs and discounts confused
// and have declared variable "cost" three times
// and you don't need it, really.
int quantityOfbreakfastOrdered, quantityOflunchOrdered, quantityOfdinnerOrdered;
double cost breakfastcostEach=0.10, lunchcostEach=0.15, dinnercostEach=0.08;
double cost breakfastdiscountPerCent=5.50, lunchdiscountPerCent=9.50, dinnerPerCent=16.50;
int cost breakfastorderMoreThan=10, lunchorderMoreThan=15, dinnerorderMoreThan=8;
cout<<"Enter the Number Of Breakfasts: "<<endl;
cin>>quantityOfbreakfastOrdered;
cout<<"Enter the Number of Lunches "<<endl;
cin>>quantityOflunchOrdered;
cout<<"Enter the Number of Dinners: "<<endl;
cin>>quantityOfdinnerOrdered;
// your variables are local; you have to call your calcDiscount
// function from within main(), so all that stuff you have in
// your print() function needs to go here instead.
// then, you need to do all of your output display as per your assignment
// then, you need to end your main() function
// **HERE**
// you need a closing parenthesis at the end of this
double calcDiscount (int quantity, double costEach, double discountPerCent, int orderMoreThan
{
if(quantity> orderMoreThan) // you've got your less than < and greater than > confused
// you don't want to return here... you want to perform your calculation the same way
// but without applying the discount. Calculate the discount based on your logic (but
// switch your < and >). If they didn't order enough to get a discount, then don't use
// your discount multiplier to reduce the cost.
return discount=0; // you need to declare a discount variable before using it.
if(quantity< orderMoreThan) // other way around
// in both cases, you want to start with (quantity*costEach)
// but if there is a discount, you want to apply the discount first
return discount=(quantity*costEach)*discountPerCent;
)
// this print function is unnecessary
void print()
{
// since you need to keep a running total, you can't simply output these values
// you need to store the return value, and add to it each time you call the
// calcDiscount function
// here is an idea to get you started, but in the main() function, not in this weird print function:
// double total = 0.0;
// total+=calcDiscount(quantityofbreakfastoOrdered, breakfastcostEach, breakfastdiscountPerCent, breakfastorderMoreThan)
cout<<calcDiscount( quantityofbreakfastoOrdered, breakfastcostEach, breakfastdiscountPerCent, breakfastorderMoreThan)<<endl;
cout<<calcDiscount(quantityoflunchOrdered, lunchcostEach, lunchdiscountPerCent, lunchorderMoreThan)<<endl;
cout<<calcDiscount(quantityofdinnerOrdered, dinnercostEach, dinnerdiscountPerCent, dinnerorderMoreThan)<<endl;
}
return 0; // this needs to go where **HERE** is
} // followed by this
|