Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2009, 04:49 PM
Schoolguy56 Schoolguy56 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 2 Schoolguy56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 29 sec
Reputation Power: 0
Problems with a Pizza menu

Hello All,

In school we have been using Ruby for our Logic Structures Class. We have been building a Pizza Menu that allows the customer to select items and then at the end add up the price and display back to the customer the items they have selected.

I went a differant way from our instructor and built a script useing a loop so you could order as many menu items as you want. The problem I am running up agianst is that while I can get it to run I cant get it to store the item or add up the price.

PHP Code:
"\n 1)  Southwestern Large 17.95                  17) House Mized Green Large 3.50" +
    
"\n 2)  Southwestern Small 10.95                  18) House Mixed Green Small 1.95" +
    
"\n 3)  Pizza Margherite Large 10.95              19) Mozzarella Caprese 7.95" +
    
"\n 4)  Pizza Margherite Small 8.95" +
    
"\n 5)  Pepperoni Classico Large 17.95            Starters" +
    
"\n 6)  Pepperoni Classico Small 10.95            20) Antipasto Platter 7.95" +
    
"\n 7)  Hawaiian Pizza Large 17.95                21) Cheese Bread 5.95" +
    
"\n 8)  Hawaiian Pizza Small 10.95                22) Breadsticks and Dip 2.50" +
    
"\n 9)  Greek Pizza Large 17.95" +
    
"\n 10) Greek Pizza Small 10.95                   Pasta" +
    
"\n 11) Pesto Eggplant Large 17.95                23) Fusilli Lunghi 13.25" +
    
"\n 12) Pesto Eggplant Small 10.95                24) Fettuccine Alfredo 14.75" +
    
"\n 13) Wild Mushrooms and Artichokes Large 17.95 25) Lasagna Fresco 12.75" +
    
"\n 14) Wild Mushrooms and Artichokes Small 10.95" +
    
"\n\n Drinks                                        Desert" +
    
"\n 15) Sodas with Refils 1.75                    26) Soumoni 2.95" +
    
"\n 16) Cofee and Tea 1.25                        27) Chocolate Lava Cake 5.00" +
    
"\n 28) Finished Ordering" +
  
    
$order STDIN.gets
    $order
.chop!
   
end
   
   def get_price
     suborder
=$order.to_i
  
    
    
case (suborder)
      
when 1
        $total 
17.95
        $menuitem 
"Southwestern Large"
      
when 2
        $total 
10.95
        $menuitem 
"Southwestern Small"
      
when 3
        $total 
10.95
        $menuitem 
"Pizza Margherite Large"
      
when 4
        $total 
8.95
        $menuitem 
"Pizza Margherite Small"
      
when 5
        $total 
17.95
        $menuitem 
"Pepperoni Classico Large"
      
when 6
        $total 
10.95
        $menuitem 
"Pepperoni Classico Small"
      
when 7
        $total 
=  17.95
        $menuitem 
"Hawaiian Pizza Large"
      
when 8
        $total 
10.95
        $menuitem 
"Hawaiian Pizza Small"
      
when 9
        $total 
17.95
        $menuitem 
"Greek Pizza Large"
      
when 10
        $total 
10.95
        $menuitem 
"Greek Pizza Small"
      
when 11
        $total 
17.95
        $menuitem 
"Pesto Eggplant Large"
      
when 12
        $total 
10.95
        $menuitem 
"Pesto Eggplant Small"
      
when 13
        $total 
17.95
        $menuitem 
"Wild Mushrooms and Artichokes Large"
      
when 14
        $total 
10.95
        $menuitem 
"Wild Mushrooms and Artichokes Small"
      
when 15
        $total 
1.95
        $menuitem 
"Sodas with Refills"
      
when 16
        $total 
1.25
        $menuitem 
"Coffee and Tea"
      
when 17
        $total 
3.50
        $menuitem 
"House Mixed Green Large"
       
when 18
        $total 
1.95
        $menuitem 
"House Mixed Green Small"
      
when 19
        $total 
7.95
        $menuitem 
"Mozzarella Caprese"
      
when 20
        $total 
7.95
        $menuitem 
"Antipasto Platter"
      
when 21
        $total 
5.95
        $menuitem 
"Cheese Bread"
      
when 22
        $total 
2.50
        $menuitem 
"Breadsticks and Dip"
      
when 23
        $total 
13.25
        $menuitem 
"Fusilli Lunghi"
      
when 24
        $total 
14.75
        $menuitem 
"Fettuccine Alfredo"
      
when 25
        $total 
12.75
        $menuitem 
"Lasagna Fresco"
      
when 26
        $total 
2.95
        $menuitem 
"Spumoni"
      
when 27
        $total 
5.00
        $menuitem 
"Chocolate Lava Cake"
      
when 28
        $total 
0
      end
  
    end 

This is the loop I have been useing.
PHP Code:
 loop do
   
     
Eight_Ball.get_order
     Eight_Ball
.get_price
     puts $total
     puts $menuitem
 
break if $order == "28" 


Any help you guys can give me is appreciated. As stated earlier I just need a way to add the price up and also to store the menuitems. that way when they exit the loop it will give them the list of what they ordered and the subtotal price.
Thanks in advance

Reply With Quote
  #2  
Old December 8th, 2009, 10:50 AM
xml-profi xml-profi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 190 xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level)xml-profi User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 7 h 8 m 25 sec
Reputation Power: 48
Send a message via ICQ to xml-profi
Code:

class Pizza
  def initialize()
  end #def initialize
  def list()
    print <<EOF
     1)  Southwestern Large 17.95                  17) House Mized Green Large 3.50
     2)  Southwestern Small 10.95                  18) House Mixed Green Small 1.95
     3)  Pizza Margherite Large 10.95              19) Mozzarella Caprese 7.95
     4)  Pizza Margherite Small 8.95
     5)  Pepperoni Classico Large 17.95            Starters
     6)  Pepperoni Classico Small 10.95            20) Antipasto Platter 7.95
     7)  Hawaiian Pizza Large 17.95                21) Cheese Bread 5.95
     8)  Hawaiian Pizza Small 10.95                22) Breadsticks and Dip 2.50
     9)  Greek Pizza Large 17.95
     10) Greek Pizza Small 10.95                   Pasta
     11) Pesto Eggplant Large 17.95                23) Fusilli Lunghi 13.25
     12) Pesto Eggplant Small 10.95                24) Fettuccine Alfredo 14.75
     13) Wild Mushrooms and Artichokes Large 17.95 25) Lasagna Fresco 12.75
     14) Wild Mushrooms and Artichokes Small 10.95
     Drinks                                        Desert
     15) Sodas with Refils 1.75                    26) Soumoni 2.95
     16) Cofee and Tea 1.25                        27) Chocolate Lava Cake 5.00
     28) Finished Ordering 
EOF
  end
  def vote
  @total=0
  list
  STDOUT.print "choose"
  STDOUT.flush
    while guess = STDIN.gets
    list
    STDOUT.print "choose"
    STDOUT.flush
    guess.chop!
    STDOUT.print "> #{guess} <\n"
    if guess == 28.to_s
    exit()
    end #if
    @total+=case guess.to_i
    
    when 16
    1.25
    when 15
    1.75
    when 18
    1.95
    when 22
    2.50
    when 26
    2.95
    when 17
    3.50
    when 27
    5.00
    when 21
    5.95
    when 19,20
    7.95
    when 4
    8.95
    when 2,3,6,8,10,12,14
    10.95
    when 25
    12.75
    when 23
    13.95
    when 24
    14.75
    when 1,5,7,11,13
    17.95
   
    else
    arrPrice[2]
    end
    STDOUT.print "TOTAL : #{@total}\n"
    STDOUT.flush
    end #while
  
  
  
  
  end #def vote
  
end #class Pizza 

t=Pizza.new
t.vote
__________________
Helmut Hagemann Germany

fallen to the bottom of the facts?
I reach my hand and we go together


wer lesen und google kann ist klar im Vorteil
who read and google is able is clear in the advantage

Reply With Quote
  #3  
Old December 8th, 2009, 12:33 PM
L7Sqr L7Sqr is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: Constant Limbo
Posts: 989 L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level)L7Sqr User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 22 h 45 m 6 sec
Reputation Power: 362
Send a message via AIM to L7Sqr
My personal opinion is that you should manage the prices externally (flat file, or DB of sorts), or at least via a hash structure instead of a massive case statement - the maintainability (or readability for that matter) of such code sucks.
As an example, consider this
Code:
prices = 
{
   # item number => price
   1 => 12.78,
   2 => 14.62,
   3 => 100.42
}

# Now you can do something like

selection = gets.chomp.to_i
print "Price: "
puts prices[selection]
__________________
True happiness is not getting what you want, it's wanting what you've already got.

My Blog

Reply With Quote
  #4  
Old December 9th, 2009, 10:46 PM
Schoolguy56 Schoolguy56 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 2 Schoolguy56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 29 sec
Reputation Power: 0
Thanks for the help guys. I will try that first one on my script. I pared it down a bit and actually got it to work without the loop and my teacher was happy with it, but since this is the first ever script I've worked on I am gonna keep working on the loop just as practice.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Problems with a Pizza menu

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap