| jsmi2016 (7) | |
|
I am doing a project that validates the date that is inputed. I have most of the project done. Accounting for leap year, the difference in length from month to month, and changing the month thats inputed as a number to the word for that month (ie i = january) This is what I have: #include <iostream> using namespace std; int main() { int month, day, year; cout<< "Enter the numeric value for the month: "; cin >> month; cout << "Day: "; cin >> day; cout << "Year: "; cin >> year; void month::Output(ostream& outs) { switch (month) { case 1: outs << "January"; break; case 2: outs << "February"; break; case 3: outs << "March"; break; case 4: outs << "April"; break; case 5: outs << "May"; break; case 6: outs << "June"; break; case 7: outs << "July"; break; case 8: outs << "August"; break; case 9: outs << "September"; break; case 10: outs << "Octuber"; break; case 11: outs << "November"; break; case 12: outs << "December"; break; default: outs << "The date is not valid." << endl; } if(year > 1582) { if ( month > 12 || month < 1 ) { cout << "The date is not valid" << endl; } else { if((year % 400) || (year % 4)) { if((day > 1) || (day <29)) { cout << month << "," << day << year << "is a date in a leap year" << endl; } else { cout << month << "," << day << year << "is not a valid date" << endl; } } else { if((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (monnth == 10) || (month == 12)) { if((day < 1) || (day > 31)) { cout << month << "," << day << year << "is a date in a non-leap year." << endl; } } else((month == 4) || (month == 6) || (month == 9) || (month == 11)) { if((day < 1) || (day > 30)) { cout << month << "," << day << year << "is a date in a non-leap year." << endl; } else { cout << "This date is not valid." << endl; } } } } } else { cout << "This date is not valid" << endl; } return 0; } These are the error codes I am receiving, and I cannot figure out why. prog.cpp: In function ‘int main()’: prog.cpp:18:6: error: ‘month’ is not a class or namespace prog.cpp:19:1: error: a function-definition is not allowed here before ‘{’ token prog.cpp:110:1: error: expected ‘}’ at end of input Someone please help me?? Thanks!!! | |
|
|
|
| macrowav3 (23) | |
Next time, put your code in code tags like this: [code]<insert code here>[/code], as it makes the code much easier to read. Here are the problems:1. In this line, else((month == 4) || (month == 6) || (month == 9) || (month == 11)), put an else if instead of else.2. The integer "month" is spelled incorrectly in this line: if((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (monnth == 10) || (month == 12))3. You cannot declare a function in main(), as you did in this line: void month::Output(ostream& outs){, so delete it. Try reading http://cplusplus.com/doc/tutorial/functions/ for clarification on functions.4. Inside the switch statement, you are using outs << instead of cout <<, so replace those.After making these changes, your program should be up and running! | |
|
|
|