In: Computer Science
Write a program which prompts the user for the year of their birth, and which then calculates their age (ignoring the month/day). Split the program into `main`, a "prompt for year" function which tests to make sure the user's input is a valid year, and a "calculate age" function which performs the actual calculation. (You can assume the current year is 2017.)
for my intro to c++ class
#include <iostream>
using namespace std;
int a;
bool promptForYear();
int calculateAge(int year);
int main() {
bool validYear = promptForYear();
if(validYear==1)
{
int age = calculateAge(a);
cout<<"Age is "<<age;
}
else
{
cout<<"The year entered is not valid \n";
}
}
bool promptForYear() {
perpendicular : cout << "Enter year of your birth \n";
cin >> a;
if(a>1900 && a<=2017)
{
return true;
}
else
{
return false;
}
}
int calculateAge(int year) {
int age = 2017 - year;
}