Question

1) Create one php file with the 4 parts. Each part should do the following: The...

1) Create one php file with the 4 parts. Each part should do the following:

  • The 1st part of the script implements a while loop that displays odd numbers between 1 and 15.
  • The 2nd part of the script implements a for loop to display numbers between 10 and 20
  • The 3rd  part of the script includes the following variable declaration: $sales = 5000;
    Using if/elseif/else statement determine the bonus percent. Make sure to change the value of $sales to fully test the script.

            If sales is between 2000 and 3000, the percentage to calculate the bonus is .10

            If sales is between 3001 and 4000, the percentage to calculate the bonus is .20

            If sales is greater than 4000, the percentage to calculate the bonus is .30

            Anything else gets a 0 for the bonus percentage

  • The 4th part of the script uses a switch statement that compares the contents the variable $city to the case labels. If a match if found, the city’s sate is echoed to the screen and a break statement ends the switch statement. For instance, start with $city = ‘Boston’. Make sure to change the city to fully test your script.
City State

Boston

Massachusetts

Chicago

Illinois

Miami

Florida

New York

New York

the default should be 'United States' is something else is in $city

Homework Answers

Answer #1

If you have any doubts, please give me comment...

<?php

// Part-1

$i=1;

while($i<=15){

echo $i." ";

$i++;

}

echo "<br />";

// Part-2

for($i=10; $i<=20; $i++){

echo $i." ";

}

echo "<br />";

// Part-3

$sales = 5000;

if($sales>=2000 && $sales<=3000)

$bonus_pct = 0.10;

else if($sales>=3001 && $sales<=4000)

$bonus_pct = 0.20;

else if($sales>4000)

$bonus_pct = 0.30;

else

$bonus_pct = 0;

echo "Bonus Percentage: ".$bonus_pct;

echo "<br />";

//Part-4

$city = "Boston";

switch($city){

case "Boston":

echo "Massachusetts";

break;

case "Chicago":

echo "Illinois";

break;

case "Miami":

echo "Florida";

break;

case "New York":

echo "New York";

break;

default:

echo "United States";

break;

}

?>

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT