Answer to Question #161793 in C++ for Anynomous

Question #161793

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


1
Expert's answer
2021-02-07T08:55:29-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog