The problem occurs on line 79 and 85 with the > relational operator. On line 79 I'll have to use <=, but for now I'd like to take things one at a time.
The error reads: no operator "<" matches these operands.
#include <iostream>
#include <string>
using namespace std;
class DayYear
{
private:
int day;
static const string MonthDays[];
static const string Months[];
public:
DayYear()
{ day = 0; }
DayYear(int)
{ ; }
void setDay(int)
{;}
void print()
{;}
friend istream& operator>>(istream &, DayYear &);
//How do i define the following 2 operators headers, out side of the class, instead of inline?
bool operator < (DayYear &c)
{
if (day < c.day)
return true;
else
return false;
}
bool operator > (DayYear &c)
{
if (day > c.day)
return true;
else
return false;
}
bool operator == (DayYear &c)
{
if (day == c.day)
return true;
else
return false;
}
};
const int MonthDays[] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
const string MonthName[] = {"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"};
DayYear::DayYear(int d)
{
setDay(d);
}
void DayYear::setDay(int d)
{
day = d;
}
void DayYear::print()
{
int i = 0;
do
{
if (day < MonthDays[i]) //should be <=, but I'm doing thing 1 at time for now.
{
cout << "\nThe month of the day is: " << MonthName[i] << ".\n";
}
else
i++;
} while (day > MonthDays[i]);
}
istream & operator>>(istream &input, DayYear &dy)
{
int d;
do {
cout << "Enter number of days: ";
input >> d;
} while (d < 0 || d > 365);
dy.setDay(d);
return input;
}
int main()
{
DayYear call1;
cin >> call1;
call1.print();
system("pause");
return 0;
}

New Topic/Question
Reply



MultiQuote





|