my head hurts

J

Jeffrey Barrett

First, obviously this is for a class I'm in. Second, I should have
attended the last lecture. Third, I have a headache.

The assignment is to build a soda machine program that will ask the
user to pick a drink (6 choices) and then ask the user for money
(price) and then display the quantity left of the certain drink
(intitially 20).

The assignment states that I must use a) 2 parallel one-dimensional
arrays to store drink prices in the first, and quantity in the second;
b) enumerated type to represent the drink names and values of this
type to access the array elemements for each drink.)

Rather than show what I have done so far (trust me it's laughable),
could someone please just get me started in the right direction (i.e.
quick summary what exactly 'typedef enum' does and how to set up the 2
arrays in parallel).

I will put the person who helps me in my will (I'm rich I swear).
 
M

Mike Wahler

Jeffrey Barrett said:
First, obviously this is for a class I'm in. Second, I should have
attended the last lecture.

Perhaps a classmate would share his notes with you.
Third, I have a headache.

Take an aspirin. :)
The assignment is to build a soda machine program that will ask the
user to pick a drink (6 choices) and then ask the user for money
(price) and then display the quantity left of the certain drink
(intitially 20).

The assignment states that I must use a) 2 parallel one-dimensional
arrays to store drink prices in the first, and quantity in the second;
b) enumerated type to represent the drink names and values of this
type to access the array elemements for each drink.)

Rather than show what I have done so far (trust me it's laughable),
could someone please just get me started in the right direction (i.e.
quick summary what exactly 'typedef enum' does


typedef enum e
{
coca_cola, pepsi, mountain_dew, count

} drink;

Defines a type 'enum e', gives symbolic names to
three values (0, 1, 2, and 3) for that type, and creates
an alias for the type, called 'drink'. Note that 'typedef'
is not needed to solve this problem. It's just a syntax
'shortcut'.
and how to set up the 2
arrays in parallel).

int prices[count];
int quantity[count];
I will put the person who helps me in my will (I'm rich I swear).

If you're really rich, you'd just hire a programmer
to do your work for you. But of course you won't
learn anything that way.

You can get far more help if you post your code and
ask specific questions about it. Don't worry if you
think your code is 'bad', we were all beginners once.

-Mike
 
M

Malcolm

Jeffrey Barrett said:
The assignment is to build a soda machine program that will ask the
user to pick a drink (6 choices) and then ask the user for money
(price) and then display the quantity left of the certain drink
(intitially 20).

The assignment states that I must use a) 2 parallel one-dimensional
arrays to store drink prices in the first, and quantity in the second;
b) enumerated type to represent the drink names and values of this
type to access the array elemements for each drink.)
Parallel arrays aren't used much in C because we have the struct keyword.

int price[6];
int quantity[6];

will however set up your arrays.

You will also need a third parallel array for drink names.

What you need to do is

1) display the menu - drinks available, code, and price. For extra brownie
points, don't display a drink if quantity drops to zero.
2) Get the drink choice from the user. This is tricky because you need to
check for bad input and reject it.
3) Handle the money. Since you probably don't have a coin slot attached to
your computer you'll have to ask how this is to be simulated.
4) Update the quantity (easy).
5) Display the new inventory.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top