Using arrays and menus...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 5
Reputation: Butterflieq is an unknown quantity at this point 
Solved Threads: 0
Butterflieq's Avatar
Butterflieq Butterflieq is offline Offline
Newbie Poster

Using arrays and menus...

 
0
  #1
Dec 16th, 2007
Hey guys gotta quick question for ya. I'm trying to figure out the best way to write an array for the following:

(1) Hot dog 1.50
(2) Fries 1.00
(3) Lemonade .75
(4) End order
You should be allowed to keep ordering from the menu until you press 4 for End order, at which point you should see a total amount due for your entire order.

I am using menus for the code. This is what I have come up with so far.

  1. start
  2. perform housekeeping()
  3. while response not equal to quitValue
  4. perform mainLoop()
  5. endwhile
  6. perform finishUp()
  7. stop
  8.  
  9. housekeeping()
  10. declare variables
  11. open files
  12. perform displayMenu()
  13. return
  14.  
  15. displayMenu()
  16. print “1. HotDog: $1.50
  17. print “2. Fries: $1.00
  18. print “3. Lemonade: $0.75
  19. print “4. End of Order”
  20. print “Please press a number to make a selection”
  21. read response
  22. return
  23.  
  24. mainLoop()
  25. case based on response
  26. case 1
  27. perform hotDog()
  28. case 2
  29. perform fries()
  30. case 3
  31. perform lemonade()
  32. case 4
  33. perform endOfOrder()
  34. default
  35. print “Sorry. Invalid Entry.”
  36. endcase
  37. perform displayMenu()
  38. return

Now for the hotDog(), fries(), lemonade(), and endOfOrder() modules how would I go about initializing the totalCost variable and have it add up correctly for each? I presume it should be something like this:
if choice = 1 (totalCost = totalCost + 1.50)
if choice = 2 (totalCost = totalCost + 1.00)
if choice = 3 (totalCost = totalCost + 0.75)
if choice = 4 (EXIT LOOP)
output "The total cost of your order is: " totalCost

That's where I am stuck at though.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,343
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1458
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Using arrays and menus...

 
0
  #2
Dec 16th, 2007
I don't know what language that was written in -- it looks a little like cobol, but in any event you will have to translate that into c++. Shouldn't be very difficult -- just add the code between start and stop in main() then create functions for all the others.

>> how would I go about initializing the totalCost variable and have it add up correctly for each
Declare totalCost in main() and pass it to the functions.
Last edited by Ancient Dragon; Dec 16th, 2007 at 7:00 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 5
Reputation: Butterflieq is an unknown quantity at this point 
Solved Threads: 0
Butterflieq's Avatar
Butterflieq Butterflieq is offline Offline
Newbie Poster

Re: Using arrays and menus...

 
0
  #3
Dec 16th, 2007
Thanks Ancient Dragon. I haven't learned any specific languages yet. That's in line next semester. This is just the pseudocode and format that we have been taught. I found a good example which helped me visually understand how to lay it out. Thanks for your help!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,343
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1458
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Using arrays and menus...

 
0
  #4
Dec 16th, 2007
>> I haven't learned any specific languages yet
Then I'm confused about what it is that you wanted? And why post it in the C++ board if you aren't trying to learn c++ yet?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 5
Reputation: Butterflieq is an unknown quantity at this point 
Solved Threads: 0
Butterflieq's Avatar
Butterflieq Butterflieq is offline Offline
Newbie Poster

Re: Using arrays and menus...

 
0
  #5
Dec 16th, 2007
I just wanted to make sure I was on the right track as far as the logic behind my code. Needing to initialize it beforehand so I would have the right outcome for my total. I start my C++ class in a few weeks. I didn't see a section under the programming list that fit just right. Did I miss one maybe or can you recommend where I should have posted? Regardless of your confusion you still lead me in the right direction to figure out what I needed so thanks again lol.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Using arrays and menus...

 
0
  #6
Dec 17th, 2007
The array being filled with the order could simply contain the item numbers being ordered, one element per ordered item. Example, if the array contained 1,1,2,1,3,3, then 3 dogs, 1 fry, and 2 lemonades were ordered. Then at end of order, use each element of the array as an index into a cost array, which contains 1.25, 1.00, .75.

Or set up the array to be the number of items, each item being an element of the array. IOW, array[0] is for "hot dog". Example: 3,1,2 would be the same order as above. Then to total, multiply each array value with the cost array from above.
Last edited by WaltP; Dec 17th, 2007 at 12:53 am.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 37
Reputation: neosomosis is an unknown quantity at this point 
Solved Threads: 0
neosomosis's Avatar
neosomosis neosomosis is offline Offline
Light Poster

Re: Using arrays and menus...

 
0
  #7
Dec 18th, 2007
This is the translation (in diagram) for WaltP explanations:

- Suppose you're declaring an array named food
- The declaration of an array:
  1. double food[the_size_of_the_array];
- ALWAYS keep in mind that, the number of an array index starts with 0. For example, you want to declare the size the array to be 5. It starts with 0....and end with 4. Like this:

food
[0] <-- The array index number. E.g: array[0]
[1]
[2] <-- Whatever contains in the array, you decide it
[3]

- Thus, your menu should look like this (inside the PC memory):

[1] Hot dog -----------> food[0] = 1.5;
[2] Fries -----------> food[1] = 1.0;
[3] Lemonade
[4] End order ---------> This part is a lil' bit tricky. You a need while loop for it

- Play around with the menu codings, its kinda fun for me.....at first
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC