mercredi 6 mai 2015

PhP: if/else statement

You do not to change gameSetup.html which receives a game character's name, type, strength, intelligence and experience rating from the user. The gameSetup.php should receive these inputs and then test if the combined three ratings add up to more than 10. If they do the program should display an error message and a link back to gameSetup.html so that the user can try again (the output statement has been provided). Otherwise the program should process the user input as follows:

Use a selection control structure to assign values for the character's health, and a second selection control structure to assign the number of pieces of gold that the character owns. The output statements have been provided. Use the following rules to create your selection structures:

 All characters receive an initial health rating of 10. The health rating may be increased if any of the following apply:  Dwarves and Wizards add 10 their health score.  Humans add 5 to their health score if their experience is below 2  Elves add 5 to their health score if their intelligence is at least 3.

 Dwarves and Wizards are always assigned 0 pieces of gold. Humans and elves are assigned 10 pieces of gold if their health rating is above 10, otherwise humans and elves are assigned 20 pieces of gold.

This is what i got so far: my print statement is not showing up when the total is greater then 3 in the following php code. Can some give me some ideas on what i did wrong?

$charName = $_POST['charName'];
$charType = $_POST['charType'];
$charExperience = $_POST['charExperience'];
$charStrength = $_POST['charStrength'];
$charIntelligence = $_POST['charIntelligence'];
$health = 10;

if ($total > 10)
{
    print("<p>Your three rating combined cannot exceed 10 points</p>
           <p><a href = \"gameSetup.html\" >Try again</a></p>");
         $total = $charExperience + $charStrength + $charIntelligence;  
}
if( $charType "$health = 10")
{
    IF($charType == "Dwarf" or $charType == "Wizard")
    {
        $health = $health + 10;
    }
    Elseif($charType == "Human")
    {
        if($charExperience < 2)
        {
        $health = $health + 5;
        }

    }
    Elseif($charType == "Elf")
    {  
        if($charIntelligence >= 3)
        {
            $health = $health + 5;
        }

}


IF($charType == "Human" or $charType == "Elf" $health > 10)
    {
        $gold = $gold +10;
    }
    else
    {
        $gold = $gold + 20;
    }
    if($charType == "Dwarf" or $charType == "Wizard")
    {
        $gold = 0;
    }





    print ("<h1>I have created $charName!</h1>
            <p>$charName is a $charType with a strength rating of $charStrength,
            an intelligence rating of $charIntelligence, and an experience rating of
            $charExperience.</p>
            <p>$charName has a health rating of $health</p>
            <p>$charName has $gold pieces of gold. </p> ");
}

Aucun commentaire:

Enregistrer un commentaire