Jump to content
Alexander10

PHP electricity bill task

Recommended Posts

Hi my name is Alexander and i am new to coding. i am in need for tommorow for this task , but i cant figure out how to make it. Can anyone explain where is my mistake and how the code should look? I have some code but its full with errors....
Write down a program that uses the given electricity units and calculates the current electricity bill under the conditions:
For the first 50 units - 0.10 
For the next 100 - 0.15 
For the next 100 - 0.25 
For the next - 0.35 
20% VAT is added to the general account.
Input Output
150 24 
155 25,50 
201 39,30 
302 75,84 

 

 

 

Share this post


Link to post
Share on other sites

Uh....  school project?   Doesn't that imply that YOU are supposed to write something?

You write it.  We'll help you correct it.

What's wrong - you skipped too many classes to even make the attempt here?

Share this post


Link to post
Share on other sites

And why did you not post your code (PROPERLY) here so that all can help you?  Be sure you have php error checking turned on.  I'm sure they taught you that.

Share this post


Link to post
Share on other sites

Think it through. One of the things you'll see and hear about regularly in programming is 'pseudo-code' - write the steps you need the program to follow in order to solve the problem, then write the code to actually do it. So what do you need to do here?

for the first 50 units of energy energy used
	add .10 to the total bill
are there units left to bill?
	for the next 100 units of energy used
		add .15 to the total bill
are there units left to bill?
	for the next 100 units of energy used
		add .25 to the total bill
are there any units left to bill?
	for the rest of the units
		add .35 to the total bill
take the total bill and mulitply it by .2 to figure the VAT
add the VAT to the total bill

output the total bill

You need to look at conditional logic and math functions. There's a bunch of different ways you can do this, so write some code and post it here. If your throws errors post those, too.

Share this post


Link to post
Share on other sites

The message I received from the OP says to delete this post.  Guess he couldn't wait for someone to write his code.....

Share this post


Link to post
Share on other sites

I got a message with the actual code we've requested here...

OP - if you want help with the task, post the code here and let all of us take a look at it. More eyes = more help, but remember this is your homework. So we will help, but we won't write it for you.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.