Jump to content
  • Advertisement
Sign in to follow this  
MasterDario

Math Problem/Visual Basic/Pseudo Code Help

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 <- 0
gas <- 500

gas <- max( 0, gas - 80 )

if gas > 120 then
c2 <- 120
gas <- gas - 120
else
c2 <- gas
gas <- 0

if gas > 200 then
c3 <- 200
gas <- gas - 200
else
c3 <- gas
gas <- 0

price <- 10.0 + 0.10*c2 + 0.05*c3 + 0.025*gas


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!