Computer Science, asked by sravani53215, 9 months ago

Ask a user for his/her birth year encoded as two digits (like "62") and for the current year, also encoded as two digits (like "99"). Write a program to find the users current age in years.

INPUT FORMAT:

Input consists of 2 integers.

The first integer corresponds to the last 2 digits of the birth year.

The second integer corresponds to the last 2 digits of the current year.

OUTPUT FORMAT:

Print the user's current age.

Refer below sample output for formatting.

Answers

Answered by mayankpathak4513
21

Answer:Required code for the problem :

#include<iostream>

using namespace std;

int main()

{

 int a,b;

 std::cin>>a>>b;

 if(a>b)

 {

   int x = 1900+a;

 int y = 2000+b;

 std::cout<<y-x;  }

 else

 {

   int x = 2000+a;

 int y = 2000+b;

 std::cout<<y-x;    }

}

Explanation:

Answered by theresamary4866
10

Answer:

#include<iostream>

using namespace std;

int main()

{

 int a,b,a1,b1;

 std::cin>>a>>b;

 if(a>b)

 {

   a1=a+1900;

   b1=b+2000;

   std::cout<<b1-a1;

 }

 else

 {

   a1=a+2000;

   b1=b+2000;

   std::cout<<b1-a1;

 }

 return 0;

}

Explanation:

Similar questions