[Site Home] [Forum Home] [Articles] [File DB] [News Archives]

Programming -> Need help with tire program (coding)


(View original topic)


Lone Lobo - Jun-04-2005 server time
Or you could do it using GUI and do it that way...

CODE

import GUI
var brand1_ID,brand2_ID,brand3_ID,price,grandtot:int
var tax,grand:real
var gran:string
tax:=1.15
procedure procBridgestone
price:=100
grand:=price*tax
grandtot:=strint(realstr(grand,0))
GUI.Dispose(brand1_ID)
GUI.Dispose(brand2_ID)
GUI.Dispose(brand3_ID)
put "Grand total comes to: $",grandtot
GUI.Quit
end procBridgestone

procedure procGoodyear
price:=130
grand:=price*tax
GUI.Dispose(brand1_ID)
GUI.Dispose(brand2_ID)
GUI.Dispose(brand3_ID)
put "Grand total comes to: $",grand:0:2
GUI.Quit
end procGoodyear

procedure procMichelin
price:=160
grand:=price*tax
grandtot:=strint(realstr(grand,0))
GUI.Dispose(brand1_ID)
GUI.Dispose(brand2_ID)
GUI.Dispose(brand3_ID)
put "Grand total comes to: $",grandtot
GUI.Quit
end procMichelin

View.Set("nobuttonbar,nocursor,graphics:300;200,title:Tire Chooser,position:center;middle")

brand1_ID:=GUI.CreateButtonFull(maxx div 2-67,maxy div 2 +50,135,"Bridgestone ($100)",procBridgestone,0,"B",true)
brand2_ID:=GUI.CreateButtonFull(maxx div 2-67,maxy div 2,135,"Goodyear ($130)",procGoodyear,0,"G",false)
brand3_ID:=GUI.CreateButtonFull(maxx div 2-67,maxy div 2 -50,135,"Michelin ($160)",procMichelin,0,"M",false)

loop
exit when GUI.ProcessEvent
end loop



Feel free to use that... If you need any help with any of the things I mentioned, just ask

Red Squirrel - May-27-2005 server time
Yeah much easier to have the list being ID and name, and you have to type in the ID, the ID would be from 1 to (number of items). So if you enter something not in that range, it gives an error. In most languages a letter is 0 so that covers that base as well.

wtd - May-27-2005 server time
No, but small minds seldom differ.

Streety - May-27-2005 server time
Great minds obviously think alike . . . em320.gif

wtd - May-27-2005 server time
Yes. We've been following that line of reasoning elsewhere.

Streety - May-27-2005 server time
What happens when a user types in the tyre they want incorrectly? Surely it would be safer to give them a list from which they select?

syb - May-25-2005 server time
why not just use the "=" (a.k.a.: becomes) sign to change what ever varible you use for the tire picking into the number value. Then sub it into an equation that times the number of tire by the price. Then times it by 15% and last but not least add the answer to the 15% eguation to the answer of the price/amount of tires

ex:
tire band x amount requested = price

price x 15% = tax

price + tax = total price

wtd - May-24-2005 server time
Well, let me help you understand it.

A function is basically a block of code to which we give a name. Why just write out the code each time when you can give it a meaningful name. PLus, this way, you make a change in one place, and it automatically takes effect everywhere.

A function takes arguments (zero or more). These are values provided at run-time which can modify how the function works. The function then outputs a value as a result.

What happens in between is that we say "if the brand is ABC, we get XYZ result". The "case" structure just makes this easier.

So the result is that we can give the function the name of a brand of tires, and the function will spit out the price.

Da_Big_Ticket - May-24-2005 server time
Thanks for the help but im not at that level yet in turing and im getting very anxious about this program. I understand how to get the variable, like the tirebrand when someone imputs it, but i need to know how to get the program to tie a cost into each brand, so that later, I can multiply the number of tires needed but the brand, which has a cost tied into it. It is worded confusingly, i know, but if any of you can code this as simple as possible for me to understand i will pay you back somehow

wtd - May-24-2005 server time
Place this logic into a function.

CODE
function getPrice(brand : string) : int
  case brand of
     label "bridgestone": result 100
     label "goodyear": result 130
     label "michelin": result 160
     label: result 0
  end case
end getPrice


Then you might have a function to actually get the name of a brand:

CODE
function getBrand : string
  var brand : int

  loop
     put "The brand you'd like:"
     put "1) Bridgestone"
     put "2) GoodYear"
     put "3) Michelin"

     get brand

     exit when brand >= 1 and brand <= 3

     % error message
     put "Not a valid choice.  Try again."
  end loop

  case brand of
     label 1: result "bridgestone"
     label 2: result "goodyear"
     label 3: result "michelin"
     label: result ""
  end case  
end getBrand


Then you might write code like:

CODE
var brandName := getBrand
var price := getPrice (brandName)

Da_Big_Ticket - May-24-2005 server time
Basically I have to make a program that:

1) Gives a list of tires offered, and their prices (eg bridgestone-100, goodyear-130, michelin-150)

2) User types in the tire they want, the program will recognize the tire and its cost

3) User says how many tires theyd like, 4 gets them a discount of 20% on the tire itself. The price is calculated based on cost/tire ** #of tires

4) User selects yes/no as to wheter they want wheel alignment, wheel balancing, mounting, and disposal services. Each of these services has an individual price

5) the total price for everything is calculated and displayed, with tax being included.

Thanks to who ever can help. My main problem is when the user says what tire they want, I need to code it so the price is recognized for that type of tire. Look here for an example, i need turing to recongnize that when a brand is imputed it recognizes a price for it

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
else if
brand = "goodyear" then
price := 130
else if
brand = "Michelin" then
price := 160

(Showing 50 last posts, newest on top)