繁体   English   中英

试图计算需要提高到某个点的 GPA [暂停]

[英]Trying to calculate GPA needed to improve to a certain point [on hold]

除了新的 GPA 之外,我已经准备好了所有需要发布的内容。 当我通过表格 go 时它显示为零,我不确定我做错了什么。 任何帮助将不胜感激。

        $currentGPAhours =  $current_gpa * $current_total_creds;
        $desiredGPA = $current_gpa + $desired_gpa;
        $desiredGPAhours = $desiredGPA * ($current_total_credits + $current_credits);
        $GPAhoursincrease = $desiredGPAhours - $currentGPAhours;
        $newGPA = $GPAhoursincreae/$current_credits;

这是整个代码

<!DOCTYPE html>
<html lang="en">

<head> 
<title>GPA Improvement Calculator</title>
<style>
    .error {
      color: #FF0000;
    }
</style>
</head>

<body>
<h1>GPA Improvement Calculator</h1>

<p><span class="error">All form fields must be completed for the GPA calculator to function.</span> 
</p>

<?php
    $name = "";
    $email = "";
    $agree = "";
    $current_gpa = "";
    $current_total_creds = "";
    $current_credits = "";
    $desired_gpa = "";

    $name_error = "";
    $email_error = "";
    $agree_error = "";
    $current_gpa_error = "";
    $current_total_creds_error = "";
    $current_credits_error = "";
    $desired_gpa_error = "";

    if (isset($_POST['submit']))
    {
        // Name Check
        if (!empty($_POST['name']) && preg_match('/^[a-zA-Z ]*$/', $_POST['name']))
        {
            $name = $_POST['name'];
        }
        else {
            $name_error = "* Your name must contain letters and white space";
        }


        // Email Check
        if (!empty($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
        {
            $email = $_POST['email'];
        }
        else {
            $email_error = "* Invalid email format";
        }


        // Agreement Check
        if (empty($_POST['agree']))
        {
            $agree_error = "* You must agree to the terms and conditions";
        }


        // Current GPA Check
        if (!empty($_POST['current_gpa']) && (filter_var($_POST['current_gpa'], FILTER_VALIDATE_FLOAT) === false) || ($_POST['current_gpa'] > 4.0) || ($_POST['current_gpa'] < 0.0) || ($_POST['current_gpa'] == NULL))
        {
            $current_gpa_error = "* Your current GPA must be between 0.0 and 4.0";
        }
        else 
        {
            $current_gpa = $_POST['current_gpa'];
        }

        // Current Total Credits Check
        if (!empty($_POST['current_total_creds']) && (filter_var($_POST['current_total_creds'], FILTER_VALIDATE_INT) === false) || ($_POST['current_total_creds'] < 0) || ($_POST['current_total_creds'] == NULL))
        {
            $current_total_creds_error = "* Your current number of credits must be a positive integer";
        }
        else
        {

            $current_total_creds = $_POST['current_total_creds'];
        }


        // Current Semester Credits Check
        if (!empty($_POST['current_credits']) && (filter_var($_POST['current_credits'], FILTER_VALIDATE_INT) === false) || ($_POST['current_credits'] < 0) || ($_POST['current_credits'] == NULL))
        {
            $current_credits_error = "* (the number of credits this semester as an integer greater than 0)";
        }
        else 
        {
            $current_credits = $_POST['current_credits'];
        }


        // Desired GPA Check
        if (!empty($_POST['desired_gpa']) && (filter_var($_POST['desired_gpa'], FILTER_VALIDATE_FLOAT) === false) || ($_POST['desired_gpa'] < 0.0) || ($_POST['desired_gpa'] == NULL))
        {
            $desired_gpa_error = "* (your desired GPA increase must be a positive value)";
        }
        else
        {
            $desired_gpa = $_POST['desired_gpa'];
        }

        $currentGPAhours =  $current_gpa * $current_total_creds;
        $desiredGPA = $current_gpa + $desired_gpa;
        $desiredGPAhours = $desiredGPA * ($current_total_credits + $current_credits);
        $GPAhoursincrease = $desiredGPAhours - $currentGPAhours;
        $newGPA = $GPAhoursincreae/$current_credits;
    }
?>

<form method="post" action="improveGPA.php">

    Name: <input type="text" size="35" name="name" value="">
    <span class="error"><?php echo $name_error; ?></span>
    <br><br>

    E-mail: <input type="text" size="35" name="email" value="">
    <span class="error"><?php echo $email_error; ?></span>
    <br><br>

    <input type="checkbox" name="agree"  >
    I agree to the terms and conditions of this website.
    <span class="error"><?php echo $agree_error; ?></span>
    <br><br>

    Current GPA: <input type="text" size="4" name="current_gpa" value="">
    <span class="error"><?php echo $current_gpa_error; ?></span>
    <br><br>

    Current Total Credits: <input type="text" size="3" name="current_total_creds" value="">
    <span class="error"><?php echo $current_total_creds_error; ?></span>
    <br><br>

    I am taking <input type="text" size="3" name="current_credits" value="">
    <span class="error"><?php echo $current_credits_error; ?></span> credits this semester.

    If I want to raise my GPA
    <input type="text" size="4" name="desired_gpa" value="">
    <span class="error"><?php echo $desired_gpa_error; ?></span> points,
    I need a <span style="font-weight: bold;"><?php echo $newGPA; ?></span> GPA on my courses this semester.
    <br><br>

    <input type="submit" name="submit" value="Calculate">

</form>


</body>

</html>

你有一个错误的变量来划分,这个:

$newGPA = $GPAhoursincreae/$current_credits;

应该:

$newGPA = $GPAhoursincrease/$current_credits;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM