Join 136,081 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,594 people online right now. Registration is fast and FREE... Join Now!
I read don't know what is wrong what this code, I has been at it a few hours now and can't see what is the proplem??? I an error message : fatal error LNK1120: 1 unresolved externals, please help.
struct // struct declaration { int Month; int Day; int Year;
}date;
int main() {
// Intialize Array For Number Of Days In Each Month int months[12]= {31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month //Initialize array for number of month in the year const unsigned int string_month = 12; string arr[string_month] = {"January","february","March","April","May","June","July","August","September","October","November","December"};
int mm, dd, yyyy, year = 0;
cout << "This program will display date and convert number of month to string" << endl; //Prompts user for input cout << "Enter month in the form of mm: "; cin >> mm;//Get month from input cout << "Enter day in the form of dd: "; cin >> dd;//Get day from input cout << "Enter year in the form of yyyy: "; cin >> yyyy;//Get year from input cin.get();
if( mm < 1 || mm > 12 )// Validate to see if input for month is valid { cout << "INVALID month: Please try again." << endl; cin.get(); exit (1); }
if( dd < 1 || dd > months[dd-1] )// Validate to see if input for day is valid { cout << "INVALID day: Please try again." << endl; cin.get(); exit (1); }
if(leapyear(year))
cout << "is a leap year\n"; else cout << "is not a leap year\n";
cout << "You have entered: " << mm << "-" << dd << "-" << yyyy << " which " << endl; cout << yyyy << " is a leap year and it is should be." << endl; return (year % 4 == 0); { date.Year = yyyy; date.Month = mm; date.Day = dd;
Thanks for your replied, by the way what is the video you have captured below?? the lady in the blue hit the lady in the red?? where is it take palce?? look like they were in the court house or something.
Anyway thanks for piont that out, I added the FunctionCall below main and it compiled but din't work right I give up. :
struct // struct declaration { int Month; int Day; int Year;
}date;
int main() {
// Intialize Array For Number Of Days In Each Month int months[12]= {31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month //Initialize array for number of month in the year const unsigned int string_month = 12; string arr[string_month] = {"January","february","March","April","May","June","July","August","September","October","November","December"};
int mm, dd, yyyy, year = 0;
cout << "This program will display date and convert number of month to string" << endl; //Prompts user for input cout << "Enter month in the form of mm: "; cin >> mm;//Get month from input cout << "Enter day in the form of dd: "; cin >> dd;//Get day from input cout << "Enter year in the form of yyyy: "; cin >> yyyy;//Get year from input cin.get();
if( mm < 1 || mm > 12 )// Validate to see if input for month is valid { cout << "INVALID month: Please try again." << endl; cin.get(); exit (1); }
if( dd < 1 || dd > months[dd-1] )// Validate to see if input for day is valid { cout << "INVALID day: Please try again." << endl; cin.get(); exit (1); }
if(leapyear(year))
cout << "is a leap year\n"; else cout << "is not a leap year\n";
cout << "You have entered: " << mm << "-" << dd << "-" << yyyy << " which " << endl; cout << yyyy << " is a leap year and it is should be." << endl; { date.Year = yyyy; date.Month = mm; date.Day = dd;
if(dd <= months[mm -1])
cout << arr[mm - 1] << ", " << date.Day << " " << date.Year << endl; else cout << "Invalid Date for the month!";
After these changes the code works correctly, as so...
QUOTE
>$./time This program will display date and convert number of month to string Enter month in the form of mm: 01 Enter day in the form of dd: 01 Enter year in the form of yyyy: 2001 is not a leap year You have entered: 1-1-2001 which 2001 is a leap year and it is should be.
QUOTE
>$./time This program will display date and convert number of month to string Enter month in the form of mm: 01 Enter day in the form of dd: 01 Enter year in the form of yyyy: 2004 is a leap year You have entered: 1-1-2004 which 2004 is a leap year and it is should be.
I'm not sure why that you have that last line in there, that says it should be, but the logic is correct with these 2 fixes.
OK no2pencil, it work with either functionCall ( int or bool) but if it is a leap year 02-28-2004 entered by user then it should display 02-29 2004 instead??? I know I'm very close get it working.
struct // struct declaration { int Month; int Day; int Year;
}date;
int main() {
// Intialize Array For Number Of Days In Each Month int months[13]= {31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month //Initialize array for number of month in the year const unsigned int string_month = 12; string arr[string_month] = {"January","february","March","April","May","June","July","August","September","October","November","December"};
int mm, dd, yyyy, year = 0;
cout << "This program will display date and convert number of month to string" << endl; //Prompts user for input cout << "Enter month in the form of mm: "; cin >> mm;//Get month from input if( mm < 1 || mm > 12 )// Validate to see if input for month is valid { cout << "INVALID month: Please try again." << endl; cin.get(); system ("pause"); exit (1); } cout << "Enter day in the form of dd: "; cin >> dd;//Get day from input if( dd < 1 || dd > months[dd-1] )// Validate to see if input for day is valid { cout << "INVALID day: Please try again." << endl; cin.get(); system ("pause"); exit (1); } cout << "Enter year in the form of yyyy: "; cin >> yyyy;//Get year from input cin.get();
if(leapyear(year))
cout << yyyy << " is a leap year.\n"; else cout << yyyy << " is not a leap year\n";
cout << "You have entered: " << mm << "-" << dd << "-" << yyyy << " which ";// << endl; cout << "it should be: ";// << endl; { date.Year = yyyy; date.Month = mm; date.Day = dd;
if(dd <= months[mm - 1])
cout << arr[mm - 1] << ", " << date.Day << " " << date.Year << endl; else cout << "Invalid Date for the month!";
so far I got it working without any problem, one thing that I still didn't feel right about this code is that, what if user enter 02-28-2004, it tell yes that is the leapyear, but it didn't correct the date entered, it should display 2004 is the leapyear: February, 29 2004. Another problem is that if user entered 02-29-2004, then it just need to display yyyy is leapyear: February, 29 2004. This code got too complicated, all I want it to do is display the leapyear if divisible by 4 then days range from 1-29, else it is not the leapyear day range from 1-28.
CODE
year = yyyy; cout << "You have entered: " << mm << "-" << dd << "-" << yyyy << " which: "; cout << arr[mm - 1] << ", " << date.Day << " " << date.Year << endl; { lp_ck = yyyy%4; lp_ck = yyyy%4; if(lp_ck==0) if(leapyear(year)) months[1]=29; cout << yyyy << " is a leap year.\n"; else months[1]=28; cout << yyyy << " is not a leap year\n"; }
//if(leapyear(year))
//cout << yyyy << " is a leap year.\n"; //else //cout << yyyy << " is not a leap year\n";
I changed the code in check for leapyear part, it tell me that I error: [error] error C2181: illegal else without matching if [error]
OK the code now compiled cause missing the {}, but it did not display what it should, the user can not enter int months[14]= {31,28,31,30,31,30,31,31,30,31,30,31}; dd > 28 for the month of February, 29 2004 for leapyear, I have to increase the array size to 14. This part of the code did not work right, check for months[1] = 29; if it is leapyear, else months[1]=28; if not leapyear.
CODE
{ lp_ck = yyyy%4; if(lp_ck==0) //if(leapyear(year)) { months[1]=29; cout << yyyy << " is a leap year.\n"; } else { months[1]=28; cout << yyyy << " is not a leap year\n"; } }
This part is just to check to see if it is leapyear then display month = 29 instaed of 28 and display the date for leapyear, help.
This post has been edited by KMH: 13 Apr, 2008 - 04:33 PM
I can't imagine how that lady in red she probably has a very bad headache and big black eye. Anyway I got the code working now, but I don't feel right the fact that I have to increase the number of my array element to cover dd = 29 entered for February month. Perhaps this line in the code did work. [array] int months[12]= {31,28,31,30,31,30,31,31,30,31,30,31}; >>change to>>int months[14]= {31,28,31,30,31,30,31,31,30,31,30,31}; [a/rray] [line] if( dd < 1 || dd > months[dd-1] )// Validate to see if input for day is valid [/line]
struct // struct declaration { int Month; int Day; int Year;
}date;
int main() {
// Intialize Array For Number Of Days In Each Month int months[14]= {31,28,31,30,31,30,31,31,30,31,30,31}; //Array For Number Of Days In Each Month //Initialize array for number of month in the year const unsigned int string_month = 12; string arr[string_month] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
int mm, dd, yyyy, year = 0;
cout << "This program will display date and convert number of month to string" << endl; //Prompts user for input cout << "Enter month in the form of mm: "; cin >> mm;//Get month from input if( mm < 1 || mm > 12 )// Validate to see if input for month is valid { cout << "INVALID month: Please try again.\n" << endl; //cin.get(); system ("pause"); exit (1); } cout << "Enter day in the form of dd: "; cin >> dd;//Get day from input if( dd < 1 || dd > months[dd-1] )// Validate to see if input for day is valid for the month { cout << "INVALID day: Please try again.\n" << endl; cin.get(); system ("pause"); exit (1); } cout << "Enter year in the form of yyyy: "; cin >> yyyy;//Get year from input cin.get(); year = yyyy; cout << "You have entered: " << mm << "-" << dd << "-" << yyyy << " which " << endl;
if(leapyear(year) && mm == 2 && dd > months[1] + 1)// Check to see if leapyear or not cout << "Invalid # of days for the month of (" << arr[mm - 1] << ") in the year of (" << yyyy << ").\n"; else if( dd > months[1] ) cout << "Invalid # of days for the month of (" << arr[mm - 1] << ") in the year of (" << yyyy <<").\n"; else if(leapyear(year)&& mm == 2) { months[1] = 29; cout << yyyy << " is a leap year.\n"; } else { months[1] = 28; cout << yyyy << " is not a leap year\n"; } date.Year = yyyy; date.Month = mm; date.Day = dd;