Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Variable Pricing Variables, a new bar, has a very unusual pricing policy for the two drinks that it sells (called A and B here for

Variable Pricing Variables, a new bar, has a very unusual pricing policy for the two drinks that it sells (called A and B here for simplicity). At the start of each night, each drink costs $5. Each time a drink is purchased, its price goes up $1 for the next patron (the prices change independently; if someone purchases drink A, its price goes up but the price for B stays the same). In order to prevent prices from getting too high, a drink's price cannot exceed $11; after a drink is sold for $11, its price resets back to $5 and begins to rise again. For example, suppose several drinks are purchased in the following order: A, A, A, B, B, A, B. The corresponding prices for these drinks (in order) would be $5, $6, $7, $5, $6, $8, $7. Write a C program, which reads in a sequence of drink orders from the user (as a series of capital As and Bs, with no spaces or other characters). Your program should print out the total cost of all the drinks sold (in the example above, the total cost would be $44). Sample Input: AAABBAB Sample Output: 44 Hint: Your program must be able to accept a sequence of drink orders of any length, so a while loop with getchar() would probably be the best strategy here.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

Understanding Groups

Answered: 1 week ago