CalcBuilder Forum

Help making a calculator

User thiagobarreto 2020-01-21 14:43:10

Hello
I'm in doubt how to make a calculator.

need to convert a unit of weight (kg) into caloric weight, as follows:


if weight is <10kg = caloric weight is: weight x 1
if the weight is> 10kg and <20kg = (weight - 10) x 0.5 + 10
if weight is> 20 = (weight - 15) x 0.2 + 15

form:

weight: ( form )
caloric weight: ( result )

result example 1:
Weight: 7kg
Caloric Weight : 7kg

result example 2:
Weight: 15kg
Caloric Weight : 12,5kg

result example 3:
Weight: 35kg
Caloric Weight : 18kg

Moonsoft support 2020-01-22 08:55:45

Hello,
first you need to create your input fields, in this case weight, that you will receive at the code section as $weight. Then you can write your math at the code section and introduce the result into your variable (if you call it 'result', then you need to fill the $result variable, for ex):

$result=$weight*5;

For your case you also need to use 'if' clauses, so you can check the proper syntax here:

https://www.php.net/manual/en/control-structures.if.php

In order to build this kind of code

if($weight<10) {
$result=......;
}
if(.....condition...){
.....
}

And finally, you can write your result at the output section with

##result##

tag.

Hope this helps, regards

...
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!
...
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!