Math Problem/Visual Basic/Pseudo Code Help
Hi everyone, i was hoping someone could help me with this math problem that i need to implement into visual basic. Even if you guys give it in Psuedo Code it will help a lot. I can basically implement anything into visual basic but cant understand the stupid math question. Here it is:
A guy has used up 500 cubic meters of gas. Based on the following information, how much money does he owe?
first 80 cubic meters 10.00$ minimum cost
next 120 cubic meters $ 0.10 per cubic meter
next 200 cubic meters $ 0.05 per cubic meter
above 400 cubic meters $0.025 per cubic meter
:)
You're meant to implement a function, f, that takes as an argument the volume bought, and returns the total price. Once that function is implemented, your answer is f(500).
The subject basically gives you a series of rules that allows you to write the function (a specification, if you want), by giving you four products:
"first 80"
"next 120"
"next 200"
"more than 400"
Since you know the price for each of these categories, all you need to do is compute how much of each product has been bought (and from there, you get the total price).
And if you are given the total amount of gas, you can easily compute how that amount is divided into the above categories.
The subject basically gives you a series of rules that allows you to write the function (a specification, if you want), by giving you four products:
"first 80"
"next 120"
"next 200"
"more than 400"
Since you know the price for each of these categories, all you need to do is compute how much of each product has been bought (and from there, you get the total price).
And if you are given the total amount of gas, you can easily compute how that amount is divided into the above categories.
well this is actually for a visual basic class im taking and we didnt learn about functions yet, she said to use the conditional statements.
i dont know vb so i wrote in c and added the vb 'then' keyword.
a+=b means a = a + b.
i think.
about the last payment term, if the gas is larger than 400 so all the other terms are ignored?
EDIT: a simpler way will be:
and so on. (i think thats what ToohrVyk meant)
a+=b means a = a + b.
gas=500;money=0;if (gas-80>=0) then money+=(gas-80)*10.00;if (gas-80-120>=0) then money+=(gas-80-120)*0.10;if (gas-80-120-200>=0) then money+=(gas-80-120-200)*0.05;
i think.
about the last payment term, if the gas is larger than 400 so all the other terms are ignored?
EDIT: a simpler way will be:
if (gas/80>=1) then money+= ...if (gas/120>=1) then money+= ...
and so on. (i think thats what ToohrVyk meant)
although your logic sounds good, are you sure about that doesnt seem like it matches with the table. lol i dont know the way its worded is retarted.
I dont think thats right though because according to your algorithm you would get $32.00 as a result if you used up 500cubmic meters of gas. or maybe it is right i dont know lol
now that you give me that code though wouldnt this be the actual right code
gas=500;
money=0;
if (gas-80>=0)
then money+=(gas-80)*10.00;
if (gas-120>=0)
then money+=(gas-120)*0.10;
if (gas-200>=0)
then money+=(gas-200)*0.05;
now that you give me that code though wouldnt this be the actual right code
gas=500;
money=0;
if (gas-80>=0)
then money+=(gas-80)*10.00;
if (gas-120>=0)
then money+=(gas-120)*0.10;
if (gas-200>=0)
then money+=(gas-200)*0.05;
The above solution is not correct, since it makes you pay more for an additional gallon if you bought a lot of it. My solution would be:
c2, c3 <- 0gas <- 500gas <- max( 0, gas - 80 )if gas > 120 then c2 <- 120 gas <- gas - 120else c2 <- gas gas <- 0if gas > 200 then c3 <- 200 gas <- gas - 200else c3 <- gas gas <- 0price <- 10.0 + 0.10*c2 + 0.05*c3 + 0.025*gas
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement