Page 1 of 1

Need help with tire program (coding)

Posted: Tue May 24, 2005 10:10 pm
by Anonymous
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

Archived topic from Iceteks, old topic ID:3345, old post ID:27085

Need help with tire program (coding)

Posted: Tue May 24, 2005 10:41 pm
by wtd
Place this logic into a function.

Code: Select all

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[code]

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[code]

Then you might write code like:

[code]var brandName := getBrand
var price := getPrice (brandName)[code] 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3345, old post ID:27087[/size][/color]

Need help with tire program (coding)

Posted: Tue May 24, 2005 11:06 pm
by Anonymous
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

Archived topic from Iceteks, old topic ID:3345, old post ID:27088

Need help with tire program (coding)

Posted: Tue May 24, 2005 11:29 pm
by wtd
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.

Archived topic from Iceteks, old topic ID:3345, old post ID:27089

Need help with tire program (coding)

Posted: Wed May 25, 2005 6:46 pm
by syb
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

Archived topic from Iceteks, old topic ID:3345, old post ID:27100

Need help with tire program (coding)

Posted: Fri May 27, 2005 7:56 am
by Streety
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?

Archived topic from Iceteks, old topic ID:3345, old post ID:27114

Need help with tire program (coding)

Posted: Fri May 27, 2005 1:04 pm
by wtd
Yes. We've been following that line of reasoning elsewhere.

Archived topic from Iceteks, old topic ID:3345, old post ID:27117

Need help with tire program (coding)

Posted: Fri May 27, 2005 1:52 pm
by Streety
Great minds obviously think alike . . . :D

Archived topic from Iceteks, old topic ID:3345, old post ID:27119

Need help with tire program (coding)

Posted: Fri May 27, 2005 2:13 pm
by wtd
No, but small minds seldom differ.

Archived topic from Iceteks, old topic ID:3345, old post ID:27122

Need help with tire program (coding)

Posted: Fri May 27, 2005 5:13 pm
by Red Squirrel
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.

Archived topic from Iceteks, old topic ID:3345, old post ID:27127

Need help with tire program (coding)

Posted: Sat Jun 04, 2005 10:52 pm
by Anonymous
Or you could do it using GUI and do it that way...

Code: Select all

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

[code]

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

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:3345, old post ID:27247[/size][/color]