Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with a Pizza Ordering Program & Radio Buttons
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Brittney




PostPosted: Thu Jan 07, 2010 12:21 pm   Post subject: Help with a Pizza Ordering Program & Radio Buttons

What is it you are trying to achieve?
I am trying to design a Pizza Ordering program for a Culminating Activity. We need to have a pizza size, any toppings, and any extras. We then need to display a bill at the end with the subtotal, the total with taxes, the date & time, and a display of everything that you ordered.


What is the problem you are having?
The problem that I am having is that I want to use radio buttons for selection instead of using "get" inputs. The first code is my basic program. The array at the end displays numbers only, and I need the program to display strings.
The second code is my advanced prgram in which I'm experimenting with the radio butons. This is the one that I am striving to hand in and perfect, as it is easier to use and looks better. I have 3 radio buttons for size of pizza. When you select one, it for some reason displays 3 sizes instead of one, and when you press Add To Order I want it to store the data selected and then move onto the next question.


Describe what you have tried to solve this problem
I have tried to change the array names to string, but I have no idea how to do anything about this program.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Basic Program

Turing:


/* Variable Declaration  ********/
 import GUI
 View.Set ("graphics:350, 80, center, middle")
% The variables are declared
var subtotal:real := 0;
var length1, width1:real;
var numberOfPizzas:int;
var total:real := 0;
var size:int;
var toppings:int;
var extras:int;
const HST:real:= 1.13;

       
/* Mainline   *******/

put "Welcome to East Side Pizza!"

cls

 

put "How many pizzas would you like?"
get numberOfPizzas

var sizeArray : array 1 .. numberOfPizzas of int
var toppingsArray : array 1 .. numberOfPizzas of int
var extrasArray : array 1 .. numberOfPizzas of int
for a: 1 .. numberOfPizzas

cls

put "What size pizza would you like? (1. Small $5) (2. Medium $7) (3. Large $9) "
get sizeArray (a)

if sizeArray (a)=1 then
    subtotal:= subtotal + 5
    elsif sizeArray (a)=2 then
    subtotal:= subtotal + 7
    elsif sizeArray (a)=3 then
    subtotal:= subtotal + 9
end if

cls

put "What toppings would you like? $1 each. 0 for no toppings"
get toppingsArray (a)

    if toppingsArray (a)=0  then
    subtotal:= subtotal + 1
    end if

cls

put "Would you like any extras? (1. Pop $1.25) (2. Wings $5) (3. Fries $3) "
get extrasArray (a)

    if extrasArray (a)=1 then
    subtotal:= subtotal + 1.25
    elsif extrasArray (a)=2 then
    subtotal:= subtotal + 5
    elsif extrasArray (a)=3then
    subtotal:= subtotal + 3
    end if
   
end for

total:=subtotal * HST

cls

for a : 1 .. numberOfPizzas
    put "Room ", a, "'s length is: ", sizeArray (a), "m"
    put "Room ", a, "'s width is: ", toppingsArray (a), "m"
    put "Room ", a, "'s width is: ", extrasArray (a), "m"
end for

put ""
put "The subtotal is: $", subtotal
put ""
put "The total cost including taxes is: $", total



Advanced Program

Turing:


/* Variable Declaration  ********/
 import GUI
 View.Set ("graphics:350, 80, center, middle")
% The variables are declared
var subtotal:real := 0;
var length1, width1:real;
var numberOfPizzas:int;
var total:real := 0;
var size:int;
var toppings:int;
var extras:int;
const HST:real:= .13;
var radio : array 1 .. 3 of int
     
/* Mainline   *******/
   

procedure RadioPressed
            Text.Locate (1, 1)
            put "You have selected a " ..
            for i : 1 .. 3
                if radio (1) = GUI.GetEventWidgetID then
                    put "small"
                elsif radio (2) = GUI.GetEventWidgetID then
                    put "medium"
                elsif radio (3) = GUI.GetEventWidgetID then
                    put "large"
                end if
            end for
            put " pizza."
        end RadioPressed


put "Welcome to East Side Pizza!"

cls

put "How many pizzas would you like?"
get numberOfPizzas

for a: 1 .. numberOfPizzas

cls

put "What size pizza would you like? Small $5,  Medium $7, Large $9 "


        radio (1) := GUI.CreateRadioButton (15, 300,
            "Small", 0, RadioPressed)
        radio (2) := GUI.CreateRadioButton ( 15, 200, "Medium",
            radio (1), RadioPressed)
        radio (3) := GUI.CreateRadioButton ( 15, 100, "Large",
            radio (2), RadioPressed)
       
           
        var draw : int := GUI.CreateButtonFull (50, 10, 0, "Add to Order",
            RadioPressed, 0, '^D', true)

           
        loop
            exit when GUI.ProcessEvent
        end loop

cls

put "What toppings would you like? $1 each. 0 for no toppings"
get toppings

    if toppings=0  then
    subtotal:= subtotal + 1
    end if

cls

put "Would you like any extras? (1. Pop $1.25) (2. Wings $5) (3. Fries $3) "
get extras

    if extras=1 then
    subtotal:= subtotal + 1.25
    elsif extras=2 then
    subtotal:= subtotal + 5
    elsif extras=3then
    subtotal:= subtotal + 3
    end if
   
end for

total:=subtotal * HST

cls

put ""
put "The subtotal is: $", subtotal
put ""
put "The total cost including taxes is: $", total



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu Jan 07, 2010 12:51 pm   Post subject: RE:Help with a Pizza Ordering Program & Radio Buttons

I don't have time to solve your posted issue, but I can solve one you didn't mention:

code:


put "Welcome to East Side Pizza!"

cls


This will never display. You're displaying something, then erasing it right away.
StuartG




PostPosted: Thu Jan 07, 2010 5:35 pm   Post subject: RE:Help with a Pizza Ordering Program & Radio Buttons

Alright for starters in the topping section you have it set up so that if you type "0", as in you want no toppings, it charges you a dollar. But if you enter any other number it doesnt charge you for the toppings.

As for the whole radio button thing, i think it would be easier to create you're own buttons (using Draw.Box and so on) and then using Mouse.Where to locate what the user selected.

Also im having trouble understanding what you're problem is for question 1 (Sorry Sad )

Edit:

And as for the whole reason why it repeats what pizza you selected 3 times it's because of the way you set up the procedure:


Quote:
procedure RadioPressed
Text.Locate (1, 1)
put "You have selected a " ..
for i : 1 .. 3
if radio (1) = GUI.GetEventWidgetID then
put "small"
elsif radio (2) = GUI.GetEventWidgetID then
put "medium"
elsif radio (3) = GUI.GetEventWidgetID then
put "large"
end if
end for
put " pizza."
end RadioPressed


You set it up in a for loop to repeat 3 times. Why this is done i don't really know why but i dont think its necessary.
Brittney




PostPosted: Mon Jan 11, 2010 11:46 am   Post subject: RE:Help with a Pizza Ordering Program & Radio Buttons

Thank you.

Basically I want to have an array that gets the size, toppings, and extras and then displays it on the bill when the order is done.

I know how to use arrays (just the basics) but I'm not sure how to do it so that instead of numbers, it will display the actual text.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: