C++ Saved Program: calm-palace

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include<stdio.h>
int numberofyears( int age); //function prototype
int main() //main function
{
char name[30];
int age;
printf ("Enter your Name:\n"); 
scanf("%s", &name); //Reseave the name
printf("Enter your age:\n");
scanf("%d", &age); //Reseave the age
if(age>18)// checking eligibility
{
    printf("%s You are eligible to vote!\n", name);
}
else if(age<18 && age>0)
{
    printf("Sorry %s! You are not eligible to vote. You have to wait %d year/s\n", name, numberofyears(age));
}
else
{
    printf("Enter your age correctly\n");
}//End if...else statement
return 0;
}//End main function
int numberofyears(int age)// Function  to calculate the number of year that have to wait
{
    int years;
    years= (19-age);
    return years;
}// End function
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs