Write a program that asks the user for their age and lets them know if they are eligible to vote. If they are not eligible, let them know how many years they have left.
Output 1:
Enter your age as a whole number: [assume user types: 20]
You are eligible to vote!
Output 2:
Enter your age as a whole number: [assume user types: 15]
You will be eligible to vote in 3 years
Hints and Notes:
1) Use an If/Else for this
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"Enter your age as a whole number: ";
cin>>age;
if(age>=18){
cout<<"You are eligible to vote!"<<endl;
}
else{
cout<<"You will be eligible to vote in "<<18-age<<" years"<<endl;
}
return 0;
}
Comments
Leave a comment