Write a PHP program to check if a person is eligible to vote
Description: Write a PHP program to check if a person is eligible to vote or not.
Rules and hints:
- The minimum age to vote is 18.
- Use a PHP function.
- Use decision making statements.
PHP program to check voting eligibility
<?php
function checkVote($name, $age) {
if ($age >= 18) {
return $name . ", you are eligible to vote.";
}
return $name . ", you are not eligible to vote.";
}
echo checkVote("Rakesh", 19) . "<br>";
echo checkVote("Anita", 16);
?>
Output:
Tutorials Class - Output Window
Rakesh, you are eligible to vote.
Anita, you are not eligible to vote.
How it works
- The function gets the name and the age as parameters.
- If the age is 18 or more it returns the eligible message, otherwise the other message.
- We call it two times with different values.
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Decision Making |
| PHP match Expression |
| Interview Questions & Answers |
|---|
| No Content Found. |