R Lang

R Program to Check Age of a user is eligible for voting or not1 min read

In this program, You will learn how to check the age of a user is eligible for voting or not in R.

R Program Example: How to Check Age of a user is eligible for voting or not in R




This is a R program that prompts the user to enter their age and check if they are eligible to vote based on the age they enter. Here’s what the code does, step by step:

  1. The program starts by using the readline() function to prompt the user to enter their age, which is stored in the variable age. The as.integer() function is used to ensure that the age is stored as an integer.
  2. Next, the program uses an if-else statement to check if the age is greater than or equal to 18. If the age is greater than or equal to 18, it prints a message indicating that the user is valid for voting along with the age. Else, it prints that the user is not valid for voting.
  3. The function paste() concatenates the message string with the age.
  4. Finally, when the program runs it will take input from the user and give the output as the eligibility of voting of the person based on their age.

It’s important to note that different countries have different voting age requirement, in most countries 18 is the age limit but this may not be the case in every country.

Output:

Leave a Comment