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

Username:   Password: 
 RegisterRegister   
 Arrays In A Cashier Program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mr. T




PostPosted: Tue Apr 05, 2005 11:36 pm   Post subject: Arrays In A Cashier Program

In my cashier program i declared the array
code:
var foodItems : array 1 .. 5 of string

and i inserted five foods into the array.
Each food has a corresponding price.
How would I go about getting the food name from the user in order that he/she can create a price change???
HERE IS MY CODE AS OF YET
(i realize i havent outputed my intro, just ignore it for now)
----------------------------------
code:
%%%%%%%%%%%
% CASHIER %
%%%%%%%%%%%%%%%
% BLING-BLING %
%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Variable Declaration
colour (0)
colourback (7)
cls
View.Set ("offscreenonly")
var slidingTitle : int := 0
var titleFont, shopFont : int
titleFont := Font.New ("serif:80")
shopFont := Font.New ("serif:20")
var x, y, button : int
var increase :int :=5
var foodItems : array 1 .. 5 of string
foodItems (1):="CheeseBlintz"
foodItems (2):="Corn Muffin"
foodItems (3):="Cactus Juice"
foodItems (4):="Moldy Cheese"
foodItems (5):="Liver Shnitzel"
var foodPrices : array 1..5 of real
foodPrices (1):=4.59
foodPrices (2):=5.49
foodPrices (3):=9.99
foodPrices (4):=15.01
foodPrices (5):=20.33
var listOrder :int:=3
var answer :int
var addItems, addPrices:int
var foodNames :string
%Intro Procedure
%note: View.Update was the best way to avoid streaking and flickering
procedure intro
for title : 1 .. 500
    colour (0)
    colourback (7)
    cls
    Font.Draw (" Jane & Finch", title - 500, 300, titleFont, brightred)
    %%
    Font.Draw ("  Super Store ", 500 - title, 100, titleFont, brightred)
    View.Update
end for
View.Set ("nooffscreenonly") %end of animations, output will be drawn on screen
%%%Entrance Point%%%
Draw.FillBox (240, 200, 422, 230, 0)
loop
    mousewhere (x, y, button)
    if button = 0 and whatdotcolour (x, y) = white then %button is not pressed and the mouse is over the entrance point
        locate (12, 32)
        put "[ALEX YOUNG OWNS YOU]" ..
        delay (100)
    elsif button = 0 and whatdotcolour (x, y) not= white then %button is not pressed and the mouse is not over the entrance point
        locate (12, 32)
        put "[CLICK HERE TO ENTER]" ..
        delay (100)
    elsif button = 1 and whatdotcolour (x, y) = white then %entering the store if button is pressed over the entrance point
    delay (1000)   
    cls
    exit
    end if
end loop
end intro
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Innitial Output
procedure innitialOutput
drawline (1,maxy-25,400,maxy-25,0) %horizontal line for item/price list
drawline (200,0,200,maxy,0) %vertical line for item/price list
Font.Draw("Item",70,maxy-20,shopFont,brightred)
Font.Draw("Price ($)",260,maxy-20,shopFont,brightred)
for i :1..5
locate (listOrder,1) %location of each consecutive item
put foodItems(i).. %.. so that the items do not cut off the vertical line for the item/price list
listOrder+=1 %each consecutive item is located 1 line below the previous
locate (listOrder-1,30)
put foodPrices (i)
end for
end innitialOutput
View.Set ("nooffscreenonly")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Changing Around The Shop
procedure changeShop
Font.Draw("Once In A Life Time Choice",maxx-320,110,shopFont,brightred)
drawbox(maxx-330,10,maxx-5,100,0)
locate (20,53)
put "Do you wish to:"..
locate (21,40)
put "1. Add an item / corresponding price?"..
locate (22,40)
put "2. Change a price?"..
locate (23,40)
put "3. Make a Purchase?"..
locate (24,40)
put "[Enter number of choice] "..
get answer

%Input For New Items / Corresponding Prices (OPTION #1)
if answer=1 %add an item / corresponding price option was chosen
then cls
put "How many items would you like to add? "..
get addItems
addPrices:=addItems
var addFoodItems:array 1..addItems of string
for a :1..addItems
put "Item # ",a, " to be added shall be named? "..
get addFoodItems(a):*
end for

%Input for New Prices
var addFoodPrices:array 1..addPrices of real
for b:1..addPrices
put "How much should item #", b, " cost? "..
get addFoodPrices(b)
end for

cls %clears the input section

%Output For New Items
listOrder:=3 %miniature variable reset
innitialOutput %procedure displaying the original items
for a:1..addItems
locate (listOrder,1) %situated beneath the preset items in the items column
put addFoodItems(a)..
listOrder+=1
end for

%Output for New Prices
listOrder:=3 %miniature variable reset
innitialOutput %procedure displaying the original items
for b:1..addPrices
locate (listOrder,30) %situated beneath the preset prices in the price column
put addFoodPrices(b):2:2..
listOrder+=1
end for
end if

%Changing The Price Of A Specific Item









end changeShop

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
innitialOutput
changeShop

Sponsor
Sponsor
Sponsor
sponsor
Linux Addict




PostPosted: Tue May 17, 2005 3:12 pm   Post subject: Price Change

Your problem is getting the user to enter a food item and changing the price of that item, correct? Well, you can simply just re-assign a value to the variable in the array. I'm not too sure what you want to do exactly. Be more specific and I'd be glad to help!
jamonathin




PostPosted: Wed May 18, 2005 7:49 am   Post subject: (No subject)

Do you mean something like this??
Turing:
var food : array 1 .. 5 of string := init ("apple", "orange", "banana", "pizza", "hot dog")
var price : array 1 .. 5 of int := init (1, 2, 3, 4, 5)
loop
    for i : 1 .. 5
        locate (i, 1)
        put i, ". ", food (i), " - $", price (i)
    end for
    var number, value : int
    put "Which price would you like to change?"
    get number
    put "What price to change it to?"
    get value
    price (number) := value
    cls
end loop
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  [ 3 Posts ]
Jump to:   


Style:  
Search: