#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2009
    Posts
    2
    Rep 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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    191
    Rep Power
    49
    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
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Constant Limbo
    Posts
    989
    Rep Power
    363
    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
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2009
    Posts
    2
    Rep 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.

IMN logo majestic logo threadwatch logo seochat tools logo