I'm working on an exercise where I have to program a function in C++ --- This function inserts date into an ostream formatted with one of two DATE_STYLES. Declare an enum DATE_STYLE {MM_DD_YYYY, MON_DD_YYYY}; If the function receives MM_DD_YYYY it will display the date 12312018 as 12/31/2018. Leading zeros, though not stored, will be displayed. 1052019 will be displayed as 01/05/2019. If it receives MON_DD_YYYY it will be displayed as Dec 31, 2018. In this format, all months will be three characters.
Error is
LE)’: Project1.cpp:131:37: error: lvalue required as increment operand for (unsigned i = 0; i < len; ++1) ^ Project1.cpp:138:14: error: ‘Mon’ was not declared in this scope os << Mon[month(date) - 1]; ^~~ Project1.cpp:144:34: error: lvalue required as increment operand for (unsigned i = 0; i < len; ++1) ^ Project1.cpp: In function ‘unsigned int year(const Date&)’: Project1.cpp:208:1: warning: control reaches end of non-void function [-Wreturn-type] }
My Source Code void displayDate(const Date& date, ostream& os, DATE_STYLE ds) {
// if ds == MM_DD_YYYY)
if (!wellFormed(date))
{
cout << "Date Error\n";
exit(1);
}
else
if (ds == MM_DD_YYYY)
{
if (numDigits(date) == 7)
os << '0';
os << month(date) << '/';
if (nthDigit(date, 5) == 0)
os << '0';
os << day(date) << '/';
unsigned y = year(date);
unsigned len = 4 - numDigits(y);
for (unsigned i = 0; i < len; ++1)
os << '0';
os << year(date) << endl;
}
else
string Mon[12] = {"Jan ", "Feb ", "Mar ", "Apr ", "May ", "June ", "Jul ", "Aug ", "Sept ", "Oct ", "Nov ", "Dec " };
os << Mon[month(date) - 1];
if (nthDigit(date, 5) == 0)
os << '0';
os << day(date) << ",";
unsigned y = year(date);
unsigned len = 4 - numDigits(y);
for (unsigned i = 0; i < len; ++1)
os << '0';
os << year(date) << endl;
}
Aucun commentaire:
Enregistrer un commentaire