Jump to content

PHP electricity bill task


Alexander10

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 

 

 

 

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

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.