#include<iostream> using namespace std; int main() { int m, d, y,age; int month
ID: 3616422 • Letter: #
Question
#include<iostream>
using namespace std;
int main()
{
int m, d, y,age;
int month = 07, day =16, year = 1964;
cout << "Enter the current date in month,day,yearformat (i.e. xx xx xxxx)" << endl;
cin >> m >> d >> y;
age = y -(year+1);
if(m < month)
{
age = age;
}
else if (m > month)
{
age = age + 1;
}
if(m = month && d >= day)
{
age = age + 1;
}
else
{
age = age;
}
cout<< "you are " << age << "years old" <<endl;
return 0;
}
Explanation / Answer
in the line, if(m=month&&d>=day),m is assigned the value of monthrather than comparing with it. it will work correct, if(m==month&&d>=day). This program would be better if the user's birth date is also takenas input
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.