给定一个人的年龄,我们必须检查投票资格,并检查该人是否是青少年。
青少年验证:
如果人的年龄大于或等于13且小于或等于19,则该人为青少年,否则该人不是青少年。
投票资格:
如果某人的年龄大于或等于18岁,则该人有资格投票。
看程序:
在这里,我们使用两个条件,一个条件(年龄> = 13 &&年龄<= 19)用于青少年验证,第二条件(年龄> = 18)用于投票资格。
#include<iostream>
using namespace std;
int main(){
int age;
cout<<"Enter your age: ";
cin>>age;
//人是不是少年
//>=13 and <=19
if(age>=13 && age<=19)
{
cout<<"Person is Teenager"<<endl;
}
else
{
cout<<"Person is not a Teenager"<<endl;
}
//检查投票资格的条件
if(age>=18)
{
cout<<"Personl is eligible for voting"<<endl;
}
else
{
cout<<"Person is not eligible for voating"<<endl;
}
return 0;
}输出结果
First run: Enter your age: 19 Person is Teenager Personl is eligible for voting Second run: Enter your age: 14 Person is Teenager Person is not eligible for voating Third run: Enter your age: 21 Person is not a Teenager Personl is eligible for voting