Declare 3 variables for 3 different courses, and assign values to them. Using HTML form getting handled by PHP. So use 3 text boxes for 3 different courses grades Calculate the GPA and display it on the screen
Declare 3 variables for 3 different courses, and assign values to them. Using HTML form getting handled by PHP. So use 3 text boxes for 3 different courses grades Calculate the GPA and display it on the screen
New Perspectives on HTML5, CSS3, and JavaScript
6th Edition
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Patrick M. Carey
Chapter7: Designing A Web Form: Creating A Survey Form
Section: Chapter Questions
Problem 5CP2
Related questions
Question
Declare 3 variables for 3 different courses, and assign values to them. Using HTML form getting handled by PHP.
So use 3 text boxes for 3 different courses grades
Calculate the GPA and display it on the screen
Expert Solution
Step 1
Algorithm steps of HTML:
- Start
- Create an HTML document with the title "GPA Calculator".
- Create a form element with a method of "post" and an action of "calculate-gpa.php".
- Within the form element, create a heading 2 element with the text "GPA Calculator".
- Create a label element with the text "Course 1:", and an input element of type "text" with the name "course1" and an id of "course1".
- Create a label element with the text "Course 2:", and an input element of type "text" with the name "course2" and an id of "course2".
- Create a label element with the text "Course 3:", and an input element of type "text" with the name "course3" and an id of "course3".
- Create a line break element.
- Create an input element of type "submit" with the name "submit" and the value "Calculate GPA".
- End the form element.
- End the HTML document.
Algorithm steps of Php:
- Start
- Check if the submit button was clicked or not by using the isset() function in PHP.
- If the submit button was clicked, retrieve the marks obtained in each course using the $_POST superglobal variable and store them in their respective variables: $course1, $course2, and $course3.
- Calculate the total marks obtained by adding the marks in all three courses together, and store it in a variable called $total_marks.
- Calculate the GPA by dividing the total marks by 3, and store it in a variable called $gpa.
- Display the calculated GPA using the echo statement with a string message and the calculated GPA. The number_format() function is used to format the GPA with two decimal points.
- End the PHP script.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning