In Lab 6 you will complete ALL steps of lab 6-1. However, you will turn in ONLY the required items listed below. 1. Comp

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

In Lab 6 you will complete ALL steps of lab 6-1. However, you will turn in ONLY the required items listed below. 1. Comp

Post by answerhappygod »

In Lab 6 you will complete ALL steps of lab 6-1. However, youwill turn in ONLY the required items listed below.
1. Compress all code (one compressed file) in which you addedEcho statements for debugging.
<?php // get the data from the form $investment = filter_input(INPUT_POST,'investment', FILTER_VALIDATE_FLOAT); $interest_rate = filter_input(INPUT_POST,'interest_rate', FILTER_VALIDATE_FLOAT); $years = filter_input(INPUT_POST,'years', FILTER_VALIDATE_INT);
// validate investment if ( $investment === NULL || $investment === FALSE ){ $error_message = 'Investment must be avalid number.'; } else if ( $investment <= 0 ) { $error_message = 'Investment must begreater than zero.'; }
// validate interest rate else if ( $interest_rate === NULL || $interest_rate=== FALSE ) { $error_message = 'Interest rate must bea valid number.'; } else if ( $interest_rate <= 0 ) { $error_message = 'Interest rate must begreater than zero.'; } // validate years else if ( $years === NULL || $years === FALSE ){ $error_message = 'Number of years mustbe a valid whole number.'; } else if ( $years <= 0 ) { $error_message = 'Numbr of years mustbe greater than zero.'; }
// set error message to empty string if no invalidentries else { $error_message = ''; }
// if an error message exists, go to the indexpage if ($error_message != '') { include('index.php'); exit(); }
// calculate the future value $future_value = $investment; for ($i = 1; $i <= $years; $i++) { $future_value += $future_value *$interest_rate; }
// apply currency and percent formatting $investment_f = '$'.number_format($investment,2); $yearly_rate_f = $interest_rate.'%'; $future_value_f = '$'.number_format($future_value,2);?><!DOCTYPE html><html><head> <title>Future ValueCalculator</title> <link rel="stylesheet" type="text/css"href="main.css"/></head><body> <main> <h1>Future ValueCalculator</h1>
<label>InvestmentAmount:</label> <span><?php echo$investment_f; ?></span><br>
<label>Yearly InterestRate:</label> <span><?php echo$yearly_rate_f; ?></span><br>
<label>Number ofYears:</label> <span><?php echo $years;?></span><br>
<label>FutureValue:</label> <span><?php echo$future_value_f; ?></span><br> </main></body></html>
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply