Computer Science Canada Turing combination help, using elsif if statements. |
Author: | nerd93 [ Sun Feb 22, 2009 11:32 am ] |
Post subject: | Turing combination help, using elsif if statements. |
Ok, how do you make a program where there is 14 cars with 4 different combinations such as colour, style, brand, transmission. I am suppose to make a program that where you input the 4 peices of information (colour, style, brand, transmission) and it figures out the cost for you. For example, Brand Transmission Colour Style Cost BMW Automatic Blue Two Door $34695 Volvo Manual Green Four Door $28983 Except there are 14 different combinations not just 2. There are 4 cars, 4 colours, 2 style, 2 transmission. Thanks for the help! |
Author: | saltpro15 [ Sun Feb 22, 2009 12:23 pm ] |
Post subject: | RE:Turing combination help, using elsif if statements. |
what you are attempting to do is called hardcoding, by which i mean writing an if for every possibility, a much more efficient way of doing this is with an array |
Author: | The_Bean [ Sun Feb 22, 2009 1:19 pm ] |
Post subject: | Re: Turing combination help, using elsif if statements. |
If you have 4 cars, 4 colours, 2 styles, and 2 transmissions, then you have 4*4*2*2 different combinations, which is 64 unique cars. To make an 'if' for every car would suck, so give a price to each choice, then add the cost of the 4 choices together to get the final price. BMW=$25000 Automatic=$3000 Blue=$2695 Two Door=$4000 BMW+Automatic+Blue+Two Door=$34695 |
Author: | DanielG [ Sun Feb 22, 2009 9:59 pm ] |
Post subject: | RE:Turing combination help, using elsif if statements. |
what you can do is store the price in a 4d array (or a 1d array with a mapping function from 4 values), then you have an if statement for color, style, brand, and transmittion and give a numeric value to those, then you just look up the cost in your array according to those values. |
Author: | A.J [ Sun Feb 22, 2009 10:08 pm ] |
Post subject: | Re: Turing combination help, using elsif if statements. |
DanielG wrote: what you can do is store the price in a 4d array (or a 1d array with a mapping function from 4 values), then you have an if statement for color, style, brand, and transmittion and give a numeric value to those, then you just look up the cost in your array according to those values. like Daniel has suggested, mapping the 4 values into a single array would be very efficient. You could store the color, brand , etc.. like so : color * 1 + brand * 2 + transmission * 4 + car * 8 (Since I didn't read your complete question, this might not be helpful AT ALL....I apologize if that's the case ) EDIT : changed a few words |
Author: | blankout [ Tue Mar 03, 2009 7:59 pm ] |
Post subject: | Re: Turing combination help, using elsif if statements. |
The_Bean @ Sun Feb 22, 2009 1:19 pm wrote: If you have 4 cars, 4 colours, 2 styles, and 2 transmissions, then you have 4*4*2*2 different combinations, which is 64 unique cars.
To make an 'if' for every car would suck, so give a price to each choice, then add the cost of the 4 choices together to get the final price. BMW=$25000 Automatic=$3000 Blue=$2695 Two Door=$4000 BMW+Automatic+Blue+Two Door=$34695 this would by far be the easiest thing to do, just write variables for each component (car, transmission, colour, style) then just say if BMW=$395 and blue=$4 then BMW+blue=total cost |
Author: | Insectoid [ Tue Mar 03, 2009 9:04 pm ] |
Post subject: | RE:Turing combination help, using elsif if statements. |
or skip that if entirely, totalCost := brand + transmission + color + style |