Jump to content

Recommended Posts

I have a simple math formula that works beautifully (see code below) However, on some occasions where there is a second zero after the decimal point, it does not show up (ie-$100.1 should be $100.10). Is there a way to ensure that the second number displays even if it is zero?

 

 

<?php

if (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] =="male"))

$quote=31.44;

elseif (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] =="female"))

$quote=44.65;

elseif (($_POST['age'] >= 26) && ($_POST['age'] <= 30) && ($_POST['sex'] =="male"))

$quote=35.91;

elseif (($_POST['age'] >= 26) && ($_POST['age'] <= 30) && ($_POST['sex'] =="female"))

$quote=50.33;

elseif (($_POST['age'] >= 31) && ($_POST['age'] <= 35) && ($_POST['sex'] =="male"))

$quote=40.78;

elseif (($_POST['age'] >= 31) && ($_POST['age'] <= 35) && ($_POST['sex'] =="female"))

$quote=62.11;

elseif (($_POST['age'] >= 36) && ($_POST['age'] <= 40) && ($_POST['sex'] =="male"))

$quote=51.33;

elseif (($_POST['age'] >= 36) && ($_POST['age'] <= 40) && ($_POST['sex'] =="female"))

$quote=76.72;

elseif (($_POST['age'] >= 41) && ($_POST['age'] <= 45) && ($_POST['sex'] =="male"))

$quote=65.95;

elseif (($_POST['age'] >= 41) && ($_POST['age'] <= 45) && ($_POST['sex'] =="female"))

$quote=92.55;

elseif (($_POST['age'] >= 46) && ($_POST['age'] <= 50) && ($_POST['sex'] =="male"))

$quote=87.87;

elseif (($_POST['age'] >= 46) && ($_POST['age'] <= 50) && ($_POST['sex'] =="female"))

$quote=108.38;

elseif (($_POST['age'] >= 51) && ($_POST['age'] <= 60) && ($_POST['sex'] =="male"))

$quote=117.51;

elseif (($_POST['age'] >= 51) && ($_POST['age'] <= 60) && ($_POST['sex'] =="female"))

$quote=126.65;

elseif (($_POST['age'] >= 61) && ($_POST['age'] <= 64) && ($_POST['sex'] =="male"))

$quote=184.07;

elseif (($_POST['age'] >= 61) && ($_POST['age'] <= 64) && ($_POST['sex'] =="female"))

$quote=168.87;

 

//add spouse

if (($_POST['spouse_age'] >= 18) && ($_POST['spouse_age'] <= 25) && ($_POST['spouse_sex'] =="male"))

$quote+=31.44;

elseif (($_POST['spouse_age'] >= 18) && ($_POST['spouse_age'] <= 25) && ($_POST['spouse_sex'] =="female"))

$quote+=44.65;

elseif (($_POST['spouse_age'] >= 26) && ($_POST['spouse_age'] <= 30) && ($_POST['spouse_sex'] =="male"))

$quote+=35.91;

elseif (($_POST['spouse_age'] >= 26) && ($_POST['spouse_age'] <= 30) && ($_POST['spouse_sex'] =="female"))

$quote+=50.33;

elseif (($_POST['spouse_age'] >= 31) && ($_POST['spouse_age'] <= 35) && ($_POST['spouse_sex'] =="male"))

$quote+=40.78;

elseif (($_POST['spouse_age'] >= 31) && ($_POST['spouse_age'] <= 35) && ($_POST['spouse_sex'] =="female"))

$quote+=62.11;

elseif (($_POST['spouse_age'] >= 36) && ($_POST['spouse_age'] <= 40) && ($_POST['spouse_sex'] =="male"))

$quote+=51.33;

elseif (($_POST['spouse_age'] >= 36) && ($_POST['spouse_age'] <= 40) && ($_POST['spouse_sex'] =="female"))

$quote+=76.72;

elseif (($_POST['spouse_age'] >= 41) && ($_POST['spouse_age'] <= 45) && ($_POST['spouse_sex'] =="male"))

$quote+=65.95;

elseif (($_POST['spouse_age'] >= 41) && ($_POST['spouse_age'] <= 45) && ($_POST['spouse_sex'] =="female"))

$quote+=92.55;

elseif (($_POST['spouse_age'] >= 46) && ($_POST['spouse_age'] <= 50) && ($_POST['spouse_sex'] =="male"))

$quote+=87.87;

elseif (($_POST['spouse_age'] >= 46) && ($_POST['spouse_age'] <= 50) && ($_POST['spouse_sex'] =="female"))

$quote+=108.38;

elseif (($_POST['spouse_age'] >= 51) && ($_POST['spouse_age'] <= 60) && ($_POST['spouse_sex'] =="male"))

$quote+=117.51;

elseif (($_POST['spouse_age'] >= 51) && ($_POST['spouse_age'] <= 60) && ($_POST['spouse_sex'] =="female"))

$quote+=126.65;

elseif (($_POST['spouse_age'] >= 61) && ($_POST['spouse_age'] <= 64) && ($_POST['spouse_sex'] =="male"))

$quote+=184.07;

elseif (($_POST['spouse_age'] >= 61) && ($_POST['spouse_age'] <= 64) && ($_POST['spouse_sex'] =="female"))

$quote+=168.87;

 

//add children

if (($_POST['children'] >= 3))

$quote+=90.12;

elseif (($_POST['children'] == 1))

$quote+=30.04;

elseif (($_POST['children'] == 2))

$quote+=60.08;

elseif (($_POST['children'] == 3))

$quote+=90.12;?>

 

//quote value

echo "<p style='font-size:60px; color:#b7cd2d;'>$".$quote."<br />";

echo "<span style='font-size:16px;'>per month*</span></p>";

?>

//add children

if (($_POST['children'] >= 3))

$quote+=90.12;

elseif (($_POST['children'] == 1))

$quote+=30.04;

elseif (($_POST['children'] == 2))

$quote+=60.08;

elseif (($_POST['children'] == 3))

$quote+=90.12;?>

 

 

I see there's no point in trying to help some members

 

http://www.phpfreaks.com/forums/index.php/topic,217833.msg1000489.html#msg1000489

One characteristic of a well written program is separation of code and data. If your age brackets change or the amounts change, you should not need to modify your code, only put in new data values (and I don't mean going through your source code and typing in new values in the comparisons or assignment statements.) So, at a minimum, you should be using data array(s) or you should be using a database.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.