Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arrays

Status
Not open for further replies.

FURY

Programmer
Aug 9, 2001
17
GB
i know its basic stuff but im a beginner and i need to make a program that is a basic resturant/food ordering program. i have worked out the switches to move between menus but im supposed to use a 2 dimentional array (whatever that is) to store the meals and there prices so the user can just enter how many of a certain number they want ie meal number 1 x50 portions, anysuggestions?
 
hi fury,

a 2dimensional array
is nothing mor than an array of arrays -
may sound weird, but it's like that:

int mealPrice[50][2];
Now you've got an array of
50 meals with meal number and price.
You can fill it like:
meal_Price[0][0] = first meal number;
meal_Price[0][1] = price of first meal;
meal_Price[1][0] = second meal number;
meal_Price[1][1] = price of second meal;
.
.
.
meal_Price[49][0] = 50th meal number;
meal_Price[49][1] = price of 50th meal;

But all this seems weird to me:
Why don't you just COUNT the meals from one to fifty.
Then you don't need a two-dimensional array:

mealprice[0] = price of first meal;
mealprice[2] = price of second meal;
.
.
.
mealprice[49] = price of 50th meal;

Now the key of the array is the number of the meal
at te same time.
If you need a bill for 24 portions of meal no. 13
you just go:

howMany = 24;
mealNo = 13; //or however you get it (with scanf, maybe)

printf("The price of %d portions of meal no. %d is %d.",
howMany, mealNo, howMany * mealPrice[mealNo-1]);

Don't forget the "-1", because humans begin counting by 1,
C arrays begin with 0.
So meal no 13 is on array-position 12
that means:
(mealPrice[12] == price for meal no 13)

Reards,
Steven

 
thanks ill try that out in a min, :)
 
ok my first post didnt really describe the problem propely as i didnt understand it myself, the kind of thing i need to do is as follows which im told needs to use a 2dimentional array, im really stuck now
e.g.

1.Beef Burger @£1.50 A. Chips @£1.50
2.Chicken Bites @£1.60 B. Salad @£1.50
3.Vegetarian Burger @£1.80 C. Baked Potato @£1.50
4.Breakfast Burger @£1.50 D. None @£0.00
5.Scampi @£2.00

Enter Meal Number :
Enter Side order Number :
Enter Number of Portions :
Order Total =
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top