# Math Problem/Visual Basic/Pseudo Code Help

This topic is 4986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 :)

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
i dont know vb so i wrote in c and added the vb 'then' keyword.
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)

##### Share on other sites
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.

##### Share on other sites
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;

##### Share on other sites
I figured it out thanks for everyones help.

##### Share on other sites
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

• 33
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631354
• Total Posts
2999491
×