Hi,

I am writing a program to calculate the users age (in days).

I am almost done with it, but i keep running into an error:

 ``123`` ``````66 declaration of 'int year1' shadows a parameter 67 declaration of 'int month1' shadows a parameter 68 declaration of 'int day1' shadows a parameter``````

What does this mean, and how do I fix it?

(P.S. PLEASE don't make fun of my code, I know that it's not pretty, or perfect, or (most likely) efficient)

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788`` ``````#include #include #include #include #include #include #include #include #include #include using namespace std; void getCurrentDate(int&, int&, int&); void getBirthday(int&, int&, int&); int calcYears(int, int, int, int, int, int); int main() { int month, day, year, month1, day1, year1, age; getCurrentDate(month1, day1, year1); getBirthday(month, day, year); age = calcYears(year, year1, month, month1, day, day1); cout << age; //cout << "\t" << month << "\t" << day << "\t" << year << endl; //cout << "\t" << month1 << "\t" << day1 << "\t" <> month; cout << "\nEnter the day you were born: "; cin >> day; cout << "\nEnter the year you were born: "; cin >> year; cout << endl; return; } void getCurrentDate(int& month1, int& day1, int& year1) { time_t t = time(NULL); tm* timePtr = localtime(&t); // cout << "seconds= " << timePtr->tm_sec << endl; // cout << "minutes = " << timePtr->tm_min << endl; // cout << "hours = " << timePtr->tm_hour << endl; // cout << "day of month = " << timePtr->tm_mday << endl; // cout << "month of year = " << timePtr->tm_mon << endl; // cout << "year = " << timePtr->tm_year + 1900 << endl; // cout << "weekday = " << timePtr->tm_wday << endl; // cout << "day of year = " << timePtr->tm_yday << endl; // cout << "daylight savings = " << timePtr->tm_isdst << endl; int year1= timePtr->tm_year + 1900; int month1= timePtr->tm_mon + 1; int day1= timePtr->tm_mday; // cout << "\nEnter the current month: "; // cin >> month1; // cout << "\nEnter the current day: "; // cin >> day1; // cout << "\nEnter the current year: "; // cin >> year1; // cout << endl; return; } int calcYears(int year, int year1, int month, int month1, int day, int day1) { int years; years = year1 - year; if ((month > month1) || ( month == month1 && day > day1)) years = years - 1; return years; printf("\n"); }``````

Thanks,
Stephen
Don't redeclare variables with the same name as the parameter
Also....

As a general rule, if you are naming things "day", "day1", "day2", etc... then you're doing something horribly wrong.
Thanks you very much :)

Though, i would like to ask, whats so bad about using that kind of a naming scheme?
Also, is there a way to make it output in days (taking into account leap years and such) (possibly using the 'difftime' function?)

Thanks,
Stephen
Topic archived. No new replies allowed.