|
From: jansb000 <jan...@wx...> - 2001-07-30 19:22:05
|
The error means that inside a conditional statement (like "if then =
else") the compiler has detected that one of the branches is not =
returning any value.
Note: If you use more return statements in a row, only the first one =
will be executed. Returning 3 variables in the way you do is not =
possible. Alternatives are:
- use a class or struct
- use separate functions for dd, mm and yy
- use system clock notation (dd:m:yy are coded in an unsigned long)
----- Original Message -----=20
From: Tre...@ao...=20
To: dev...@li...=20
Sent: Monday, July 30, 2001 8:31 PM
Subject: [Dev-C++] Class question
I am learning how to create a class and I need help. After creating =
the=20
class and compiling my program I get the following error.=20
warning C4715: 'Date::assignDate' : not all control paths return a =
value=20
This is my class. It is supposed to validate a date entered and =
display the=20
date on the screen. =20
#include <iostream>=20
using namespace std;=20
class Date=20
{=20
public:=20
Date();=20
int assignDate(int, int, int);=20
void displayDate();=20
private:=20
int month;=20
int day;=20
int year;=20
};=20
Date::Date()=20
{=20
month =3D 0;=20
day =3D 0;=20
year =3D 0;=20
} //end of default constructor=20
int Date::assignDate(int m, int d, int y)=20
{=20
month =3D m;=20
day =3D d;=20
year =3D y;=20
if (m >=3D1 && m <=3D 12)=20
{=20
if (m =3D 2)=20
if (y % 4 =3D=3D 0)=20
if (d >=3D 1 && d <=3D 29)=20
{=20
return m;=20
return d;=20
return y;=20
}=20
else if (d >=3D 1 && d <=3D 28)=20
{ =20
return m;=20
return d;=20
return y;=20
}=20
else if (m =3D=3D 4 || m =3D=3D 6 || m =3D=3D 9 || m =3D=3D 11)=20
if (d >=3D 1 && d <=3D 30)=20
{=20
return m;=20
return d;=20
return y;=20
}=20
else if (m =3D=3D 1 || m =3D=3D 3 || m =3D=3D 5 || m =3D=3D 7 || m =
=3D=3D 8 || m =3D=3D=20
10 || m =3D=3D 11)=20
if (d >=3D 1 && d <=3D 31)=20
{=20
return m;=20
return d;=20
return y;=20
}=20
}//end loop=20
else=20
cout << "Month does not exist" << endl;=20
//end ifs=20
} //end of assignDate function=20
void Date::displayDate()=20
{=20
cout << month << "/" << day << "/" << year;=20
} //end of displayDate function=20
|