
-----------------------------------
Da_Big_Ticket
Tue May 24, 2005 8:58 pm

Tire Service Program, Need help with coding
-----------------------------------
In this program the user is required to imput information in order to come up with a bill. I realize this will be simple to you guys, but it will be a great help to me as i am stuck and the teacher i have dosent explain things.

1) A list is given of the tires offered at the store and the prices of each

2) The user selects which tire they want, the brand of tire must have its price attached with it somehow for later use

3) The user says how many tires they'd like, 4 gets them a discount of 20% on the tire cost only

4) They are required to enter y/n to wheter they want mounting, balancing, alignment, disposal, which all have costs associated with them

5) Taxes are to be included

6) A total bill is presented

Thanks again guys, can you help me out please help is needed greatly!

-----------------------------------
jamonathin
Tue May 24, 2005 9:18 pm


-----------------------------------
Here's what you should start off with.
var price : array 1 .. 4 of int := init (100, 110, 120, 130)
var tire : array 1 .. 4 of string := init ("Tire", "Michelin", "Goodyear", "Canadian Tire")
for i : 1 .. 4
    locate (i, 1)
    put i, ") ", tire (i), ": $", price (i), " each."
end for
var tire_type : int
locate (6, 1)
put "What tire number do you want?"
get tire_type
Now all you have to do is get how many tires they want; multiply that by their individual price, and if the amount is 4 then take off 20%.  tire_type, then multiply the price (tire_type) by however many tires you have]

Now for all that mounting and whatnot, just do the same thing as the tires, put them in matching array and have the cost added on.  I don't really know what all that stuff is (alignment, disposal, . . .)

Now just multiply everything by the 1.15% tax and show them what they baught in a reciept.

-----------------------------------
Da_Big_Ticket
Tue May 24, 2005 9:31 pm


-----------------------------------
oh god, i havent even used that array stuff to even know what it does, is there any way to do it like:

Font.Draw ("Time to select which tires you'd like, please type which brand you'd like from our selection.", 0, 340, questionfont, green)
Font.Draw ("Tire Makes (individual prices): Bridgestone: $100, Goodyear: $130, Michelin: $160.", 15, 320, questionfont, green)
locate (7, 3)
    get brand
    if brand = "bridgestone" then
        price := 100
    elsif brand = "goodyear" then
        price := 130
    elsif brand = "Michelin" then
        price := 160
        Font.Draw ("How many tires would you like to purchase, 4 gets you a 20% discount", 15, 270, questionfont, green)
        locate (10, 3)
        get numberoftires

or anything, im really worried because the teacher has not explained this at all to us, it is our first time using the program, and im takin it again next year

-----------------------------------
Da_Big_Ticket
Wed May 25, 2005 5:10 pm


-----------------------------------
% Author: Jesse Counter
% Completed for: Mr. Hook
% Function: Will calculate the cost of the service provided, which is the sale of tires, the mounting costs,
% wheel alignment and balance, oil change and the cost of tire disposal

%This declares the variables used within the program and define their type.
var pic, tirefont, questionfont, ansfont : int
var brand, ans : string
var price, numberoftires, tirecost : int

% This declares the values of the variables.
pic := Pic.FileNew ("e:/edstires.jpg")
tirefont := Font.New ("Verdana:20")
questionfont := Font.New ("Arial:12")
ansfont := Font.New ("Century gothic:14")
price := 0

%This draws the picture at a specific location on the screen
Pic.Draw (pic, 0, 0, picCopy)

%This will keep the welcome screen open for 4 seconds, then clear it.
delay (4000)
cls

drawfill (1, 1, 1, 1)
colourback (3)
Font.Draw ("Duff's Tires Service.", 200, 370, tirefont, green)

loop
    Font.Draw ("Time to select which tires you'd like, please type which brand you'd like from our selection.", 0, 340, questionfont, green)
    Font.Draw ("Tire Makes (individual prices): Bridgestone: $100, Goodyear: $130, Michelin: $160.", 15, 320, questionfont, green)
    locate (7, 3)
    get brand
    if brand = "bridgestone" or brand = "Bridgestone" or brand = "BRIDGESTONE" then
        price := 100
    else
        if brand = "goodyear" or brand = "Goodyear" or brand = "GOODYEAR" then
            price := 130
        else
            if brand = "michelin" or brand = "Michelin" or brand = "MICHELIN" then
                price := 160
            else
                put "we dont carry that brand, please repeat the process."
                locate (10, 3)
                put "Those tires will cost you a price of", price, "would you like to continue? y/n?"
                get ans
                put "please type the number of tires you would like, 4 or more gets you a discount!"
                get numberoftires
            end if
        end if
    end if

end loop

This is what I have so far, can someone help fiill in the holes to make it work and explain any error in my coding. This is the main step as i later have to add code to figure out mounting/balance/alignment/tire disposal etc

-----------------------------------
Paul
Wed May 25, 2005 5:23 pm


-----------------------------------
roughly done, i gotta go:

% Author: Jesse Counter
% Completed for: Mr. Hook
% Function: Will calculate the cost of the service provided, which is the sale of tires, the mounting costs,
% wheel alignment and balance, oil change and the cost of tire disposal

%This declares the variables used within the program and define their type.
var pic, tirefont, questionfont, ansfont : int
var brand, ans : string
var price, numberoftires, tirecost : int
var tiretype: int
% This declares the values of the variables.

tirefont := Font.New ("Verdana:20")
questionfont := Font.New ("Arial:12")
ansfont := Font.New ("Century gothic:14")
price := 0

%This draws the picture at a specific location on the screen


%This will keep the welcome screen open for 4 seconds, then clear it.
delay (4000)
cls

drawfill (1, 1, 1, 1)

loop
loop
cls
Font.Draw ("Duff's Tires Service.", 200, 370, tirefont, green)


    Font.Draw ("Time to select which tires you'd like, enter a number.", 0, 340, questionfont, green)
    Font.Draw ("Tire Makes (individual prices): 1. Bridgestone: $100, 2.Goodyear: $130, 3.Michelin: $160.", 15, 320, questionfont, green)
    locate (7, 3)
    get tiretype
if tiretype = 1 then
price := 100
exit
elsif tiretype = 2 then
price := 130
exit 
elsif tiretype = 3 then
price := 160
else
put "That is not a valid selection, try again"
end if
end loop
loop
put "These tires will cost: $", price, " each, continue? (y/n)"
get ans
if ans = "y" or ans = "Y" then
put "how many tires would you like, 4 or more for a discount!"
get numberoftires

put "your total without discount is: $", numberoftires*price
exit
elsif ans = "n" or ans = "N" then
exit
end if
end loop
if ans = "y" or ans = "Y" then
exit
end if
end loop


-----------------------------------
Da_Big_Ticket
Wed May 25, 2005 5:34 pm


-----------------------------------
thanks ALOT man. I will pack back everyone somehow

-----------------------------------
wtd
Wed May 25, 2005 5:37 pm


-----------------------------------
Here's what you should start off with.
var price : array 1 .. 4 of int := init (100, 110, 120, 130)
var tire : array 1 .. 4 of string := init ("Tire", "Michelin", "Goodyear", "Canadian Tire")
for i : 1 .. 4
    locate (i, 1)
    put i, ") ", tire (i), ": $", price (i), " each."
end for
var tire_type : int
locate (6, 1)
put "What tire number do you want?"
get tire_type

He'd be far better off going with an array of records approach.

A record is a compound data type.  This means that it's a piece of data which is really composed of two or more pieces of data.  In this case the two pieces of related data are the name of the brand and the price.

By combining them in a record we make them inseparable.  They can't get confused or mixed up. 

type Tire : 
   record
      brand : string
      price : int
   end record

Now, we have three brands of tires, so we need to store multiple records.  This calls for an array.

var tires : array 1..3 of Tire

Thn we can initialize the array like so:

tires (1).brand := "Bridgestone"
tires (1).price := 100

tires (2).brand := "Goodyear"
tires (2).price := 130

tires (3).brand := "Michelin"
tires (3).price := 160

-----------------------------------
Da_Big_Ticket
Wed May 25, 2005 6:03 pm


-----------------------------------
ok im starting to see what you are getting at, its just im not knowledgable about this program enough to fully understand that wtd. I really appreciate your help though, its good to know people arent self centerd on this site and are willing to put time into other peoples issues.

-----------------------------------
wtd
Wed May 25, 2005 6:15 pm


-----------------------------------
Now you present the user with three choices (the different brands) and ask for a number (1, 2 or 3) in response.  

Clearly, if it's anything other than one of those it's invalid and we have to ask again.

So, potentially we have a loop.

loop

end loop

Now, we need to prompt for a choice:

loop
   put "Choose one"

end loop

And, we need to output the brand name and price of each option.  Fortunately, we have that bit of info already.  We can loop over that array to output this information.

loop
   put "Choose one"

   for i : 1..3

   end for
end loop

Inside the "for" loop, what should we do?  Well, we wantto output the number, the name, and the price.

loop
   put "Choose one"

   for i : 1..3
      put i, ") ", tires (i).brand, " for $", tires (i).price, " each."
   end for
end loop

Now, we need to get an integer.  We'll need an integer variable.

var choice : int

loop
   put "Choose one"

   for i : 1..3
      put i, ") ", tires (i).brand, " for $", tires (i).price, " each."
   end for
end loop

Now, we need to get an integer from the user.

var choice : int

loop
   put "Choose one"

   for i : 1..3
      put i, ") ", tires (i).brand, " for $", tires (i).price, " each."
   end for

   get choice
end loop

Now, if the choice is one of the ones we approve, we need to exit the loop.  That way the question won't be asked again.

var choice : int

loop
   put "Choose one"

   for i : 1..3
      put i, ") ", tires (i).brand, " for $", tires (i).price, " each."
   end for

   get choice

   exit when choice >= 1 and choice 