Tire Service Program, Need help with coding
Author |
Message |
Da_Big_Ticket
|
Posted: Tue May 24, 2005 8:58 pm Post subject: 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!
Description: |
|
Download |
Filename: |
eds tire2.t |
Filesize: |
1.63 KB |
Downloaded: |
168 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
jamonathin
|
Posted: Tue May 24, 2005 9:18 pm Post subject: (No subject) |
|
|
Here's what you should start off with.
Turing: | 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%. [ Hint, get the 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
|
Posted: Tue May 24, 2005 9:31 pm Post subject: (No subject) |
|
|
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
|
Posted: Wed May 25, 2005 5:10 pm Post subject: (No subject) |
|
|
code: | % 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
|
Posted: Wed May 25, 2005 5:23 pm Post subject: (No subject) |
|
|
roughly done, i gotta go:
code: |
% 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
|
Posted: Wed May 25, 2005 5:34 pm Post subject: (No subject) |
|
|
thanks ALOT man. I will pack back everyone somehow
|
|
|
|
|
|
wtd
|
Posted: Wed May 25, 2005 5:37 pm Post subject: (No subject) |
|
|
jamonathin wrote: Here's what you should start off with.
Turing: | 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.
Turing: | 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.
Turing: | var tires : array 1..3 of Tire |
Thn we can initialize the array like so:
Turing: | 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
|
Posted: Wed May 25, 2005 6:03 pm Post subject: (No subject) |
|
|
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.
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Wed May 25, 2005 6:15 pm Post subject: (No subject) |
|
|
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.
Now, we need to prompt for a choice:
code: | 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.
code: | 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.
code: | 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.
code: | 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.
code: | 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.
code: | 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 <= 3
end loop |
Now, I know the user's choice is a valid one.
Presuming, I'ved gotten the number of tires from the user, I can simply use the number the user input for their choice to look up the right price in the array.
code: | tires (choice).price |
|
|
|
|
|
|
Da_Big_Ticket
|
Posted: Wed May 25, 2005 6:39 pm Post subject: (No subject) |
|
|
alright, this is what ive got so far, now i just need to add in the mounting, balance, tire disposal etc
code: | % 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.
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)
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, 1)
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
if numberoftires <=3 then
put "your total without discount is: $", numberoftires*price
else
put "your total with a discount is: $", numberoftires*price*0.8
end if
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 |
|
|
|
|
|
|
wtd
|
Posted: Wed May 25, 2005 6:44 pm Post subject: (No subject) |
|
|
For the love of everything sweet and decent please use indentation. Also, please remove the pointless comments. Comments should tell you something about what's going on that the code itself doesn't.
code: | %This will keep the welcome screen open for 4 seconds, then clear it.
delay (4000)
cls |
I know that keeps the screen open for 4 second, thenclears it. If you have to use a comment, use the comment to tell me why you're doing that.
Also a general suggestion: get the core of the program down before you fiddle with pictures and fonts and what not. You don't know what arrays or records are and you're cluttering your code with mage loading code and what not? That's insane.
|
|
|
|
|
|
Da_Big_Ticket
|
Posted: Wed May 25, 2005 7:14 pm Post subject: (No subject) |
|
|
code: | % 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, mount,alignment, balance, disposal : string
var price, numberoftires, tirecost, mountcost, aligncost, balancecost, disposalcost : int
var tiretype: 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
mountcost:= 0
balancecost:= 0
disposalcost:= 0
aligncost:= 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)
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, 1)
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
if numberoftires <=3 then
put "your total without discount is: $", numberoftires*price
else
put "your total with a discount is: $", numberoftires*price*0.8
end if
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
put "Would you like mounting? (y/n)"
get mount
if mount = "y" or mount = "Y" then
mountcost := 20
put "Would you like alignment? (y/n)"
get alignment
if alignment = "y" or alignment = "Y" then
aligncost := 30
put "would you like balancing? (y/n)"
get balance
if balance = "y" or balance = "Y" then
balancecost := 30
put "Would you like tire disposal? (y/n)"
get disposal
if disposal = "y" or disposal = "Y" then
disposalcost := 10
put "Your final bill is $" disposalcost+balancecost+aligncost+mountcost
end if
end if
end if
end if |
|
|
|
|
|
|
|
|