Hi all, I'm having issues with a program for an assignment. The program should have 3 functions to determing the number of days fron January 1st, whether or not the year is a leap year, and if the date exists.
I want to pass an array (with the number of days in each month) to a function that, given the month and day of the month, determines if the day of the month actually exists (eg. jan 43 returns false).
Here's my code at the moment,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>
int year, month, day, days;
bool isLeapYear(int year)
{
bool isLeap;
if((year%4)==0)
{
isLeap=true;
if((year%100)==0&&year>1582&&(year%400)!=0)
isLeap=false;
}
}
int findDaysBefore(int month)
{
if(month<3)
days=31*(month-1);
else
days=30*(month-3)+(4*(month-2))/7+59;
}
bool dateIsValid(int month, int day, int days[])
{
if(0<month<13)
{
dateIsValid=true;
if 0<day<=days[month]
dateisvalid=true;
}
else
dateIsValid=false;
}
using namespace std;
int main()
{
ifstream fin("date2.txt");
ofstream fout("D_F_Jan1.txt");
int y=0, m=0, d=0, ds=0;
bool ly, valid;
int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
while (fin >> y >> m >> d)
{
fout << "For an input date of" << setw(5) << y << setw(3) << m <<
setw(3) << d << ", " << "the total number of Days from Jan 1 is: ";
ds=findDaysBefore(m);
ly=isLeapYear(y);
valid=dateIsValid(m, d, days);
if (valid=false)
fout << "Date is invalid.\n";
else
fout << ds+ly <<"\n";
}
}
|
and the errors:
63 C:\Documents and Settings\***\main.cpp assignment of function `bool dateIsValid(int, int, int*)'
63 C:\Documents and Settings\***\main.cpp cannot convert `bool' to `bool ()(int, int, int*)' in assignment
64 C:\Documents and Settings\***\main.cpp expected `(' before numeric constant
68 C:\Documents and Settings\***\main.cpp assignment of function `bool dateIsValid(int, int, int*)'
68 C:\Documents and Settings\***\main.cpp cannot convert `bool' to `bool ()(int, int, int*)' in assignment
I appreciate all help and advice. I don't have time to rewrite the whole thing (studying for mid terms), I only really need help with that function determining the validity of the date or if you see anything else that will cause incorrect results. If you want to offer other tips adressing the style or the rest of the program I appreciate it, but won't really be able to change it unless I have to.
Thanks!!!