### Help with my basic programming homework

assignment:

A college coffee shop allows students to charge coffee drinks and then bills them at the end of each month. Write a C++ program to determine the monthly bill for the student using the details below. For input, collect the following information:

The number of coffees, lattes, and mochas purchased
A single-character customer code (S for students or F for faculty/staff)
The initial cost will be based on the following:

Type Cost Each
Coffee \$1.35
Latte \$3.15
Mocha \$3.45

Tally up the total amount to be charged to a customer based on the number of each type purchased multiplied by the unit cost for the drink.

Next, offer all customers a volume discount using the following scheme.

If total charged is ...

up to \$20 -- 3% discount
at least \$20, but still under \$40 --5% discount
\$40 to \$60 --10% discount
over \$60 pounds but not over \$75 --15% discount
above \$75 --20% discount

So what I'm having trouble with is getting the output to show after the second discount because its not showing up. Would appreciate someone to check my code and see what i'm doing wrong.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576`` ``````// // #include using namespace std; int main() { //Declare Variables char student, faculty; int coffe, latte, mocha; int totaldrinks; double discountamount1; double discountamount2; double discountamount3; double discountamount4; double discountamount5; double aftervolume1; double aftervolume2; double aftervolume3; double aftervolume4; double aftervolume5; const double discount1 = .03; const double discount2 = .05; const double discount3 = .1; const double discount4 = .15; const double discount5 = .2; //Prompt if student or faculty cout << "Input a S if customer is a student or F if customer is faculty: "; cin >> student || faculty; cout << "Enter the amount of coffees, lattes, and mochas the customer has ordered: "; cin >> coffe >> latte >> mocha; //Calculation for the total for the drinks totaldrinks = (coffe * 1.35) + (latte * 3.15) + (mocha * 3.45); //Calculations for volume discounts discountamount1 = (totaldrinks * discount1); aftervolume1 = (totaldrinks - discountamount1); discountamount2 = (totaldrinks * discount2); aftervolume2 = (totaldrinks - discountamount2); discountamount3 = (totaldrinks * discount3); aftervolume3 = (totaldrinks - discountamount3); discountamount4 = (totaldrinks * discount4); aftervolume4 = (totaldrinks - discountamount4); discountamount5 = (totaldrinks * discount5); aftervolume5 = (totaldrinks - discountamount5); if(totaldrinks < 20) cout << aftervolume1 << " After your 3% discount for ordering up to \$20 for the month your balance is: " ; else if(totaldrinks >= 20 && totaldrinks < 40) cout << aftervolume2 << " After your 5% discount your balance is: " ; else if (totaldrinks >= 40 && totaldrinks <= 60) cout << aftervolume3 << " After your 10% discount your balance is: " ; else if (totaldrinks > 60 && totaldrinks <= 75) cout << aftervolume4 << " After your 15% discount your balance is: " ; else (totaldrinks > 75) cout << aftervolume5 << " After your 20% discount your balance is: " ; return 0; }``````
Last edited on
This `cin >> student || faculty;` does not work like you expect. Because the priority of `>>` is higher than the priority of `||`, what you actually get is `(cin >> student) || faculty;` which is the same as `cin >> student`.
What you probably wanted is something like this:
 ``123`` ``````char person; cout <<"Input a S if customer is a student or F if customer is faculty: "; cin >> person;``````

If person is equal to 'S', you know it's a student and otherwise it's a faculty / staff member.

And now to your question: only one of the Discount messages is showing up because only one of the conditions is met (totaldrinks cant be less than 20 and greater than or equal to 40 at the same time for example), and because you are using `else if` all the time. But this seems perfectly valid to me in the given context. Why should a customer get more than one discount?
Thank you very much for your reply! I did not do a very good job at asking my question. I guess what I'm trying to say is if i input say, 20 coffees, 3 lattes, and 10 mochas. All i get from the command prompt is "press any key to continue." I will get an output it seems up to the 5% discount mark but after that it seems to cut off.
Last edited on
In line 71 you forgot an `if` (has to be `else if` too). The sourcecode you've provided above doesn't even compile, so i guess you simply executed an older version without any output statement.
Topic archived. No new replies allowed.