Write a C++ program to find out whether the given age is eligible for voting using go to and break statement.
Answers
Answer:
Explanation:C++ Goto Statement tutorial for beginners and professionals with examples on constructor, if-else, switch, break, continue, comments, arrays, ... Let's see the simple example of goto statement in C++. ... are not eligible to vote!\n";; cout<<"Enter your age:\n";; int age;; cin>>age;; if (age < 18){; goto ineligible;; } ... List of Programs
Answer:
Example of if-else statement in C++: In this program, we will take age of a persona and checking person is teenager or not and he is eligible for voting or not?
Given age of a person and we have to check voting edibility and check person is teenager or not.
Teenage validation:
If person’s age is greater than or equal to 13 and less than or equal to 19, than person is teenager otherwise person is not a teenager.
Voting edibility:
If person’s age is greater than or equal to 18, person is eligible for voting.
Consider the program:
Here, we are using two conditions one (age>=13 && age<=19) for teenage validation and second (age>=18) for voting eligibility.
Explanation:
#include<iostream>
using namespace std;
int main()
{
int age;
cout<<"Enter your age: ";
cin>>age;
//person is teenager or not
//>=13 and <=19
if(age>=13 && age<=19)
{
cout<<"Person is Teenager"<<endl;
}
else
{
cout<<"Person is not a Teenager"<<endl;
}
//condition to check voting eligility
if(age>=18)
{
cout<<"Personl is eligible for voting"<<endl;
}
else
{
cout<<"Person is not eligible for voating"<<endl;
}
return 0;
}