Lesson 2: Functions
Activity 3: Calculating if a Person is Eligible to Vote or Not
Include the header file in the program to print the output as shown here:
#include <iostream>
Now, create a function named byreference_age_in_5_years and the if loop with the following condition to print the message:
void byreference_age_in_5_years(int& age) { if (age >= 18) { std::cout << “Congratulations! You are eligible to vote for your nation.” << std::endl; return;
Add the else block to provide another condition if the age of the user is less than 18 years:
} else{ int reqAge = 18; int yearsToGo = reqAge-age; std::cout << “No worries, just “<< yearsToGo << “ more years to go.” << std::endl; } }
In the main function, create a variable of type integer and pass it as a reference in the byreference_age_in_5_years function as shown:
int main() { int age; std::cout << “Please enter your age:”; std::cin >> age; byreference_age_in_5_years...