Write a C++ program to input users age and display a message you can vote or cannot vote.

Q16. Write a C++ program to input users age and display a message you can vote or cannot vote.

Solution:

#include<iostream.h> //standard input/output header file

#include<conio.h> //for clrscr()

 

int main()

{

int age;

 

clrscr(); //for clearing the screen

 

cout<<“\n Enter your age: “;

cin>>age;

 

age>=18?cout<<“\n You can vote.” : cout<<“\n You cannot vote.”;

 

getch(); //holds the screen until any key is pressed

return 0; //makes main() finish

}

 

OUTPUT:

CASE 1:

Enter your age: 7

 

You cannot vote.

 

CASE 2:

Enter your age: 28

 

You can vote.

Leave a Reply

Your email address will not be published. Required fields are marked *