by the way i think this is not right
this should be
does it not give you any compile time error/?
where did you declare
day!? where is the mm declaration!? i assume they are mistyped!
and there are couple of errors !( dangling! if and lost braces! i think)
your main function should be sth like this
Code:
#include <iostream>
using namespace std;
int calculate(void);
int main()
{
int a;
cout<<"enter the date(mm-dd-yy)";
cout<<calculate(); //because actually you didnt return anything from your function! you must specify the return value! rather than 0, if there is no return value , why bother declaring it as int calculate()?,
return 0;
}
line 35 :
Code:
cout<<"enter the date(mm-dd-yy);
lacks a " mark at the end of the string! before ;.
Code:
cout<<"enter the date(mm-dd-yy)";
line 36:
this is not a class! and you did not make an object out of that class! so this is wrong! instead you should have written :
which implies that the returned value
form function "calculate" should be copied into variable 'a' . but in your case this is wrong too! because in calculate it is not clear which variable should be returned!
so i would write
Code:
cout<< calculate();
and as the others mentioned before, use int main () instead of void main()
---------------
to omit the error:
you get , you must put enclose the if statements in braces so this means
instead of
Code:
if(m==1,m==3,m==5,m==7,m==8,m==10,m==12)
{
days=31;
else if(m==4,m==6,m==9,m==11)
{
days=30;
}
you must write
Code:
if( m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m==12 )
{
days = 31;
}
by the way please note that , i replaced all of comas ',' with '||' which i think i makes more sense! because i think you indented to
OR the conditions! and for that we use '||' , if you use coma, that just make a logic error!it wont or the conditions!
the same thing goes here too
instead of
Code:
else if(m==2&&day<=28)
{
cout<<"yout date is correct";
else
{
cout<<"invalid date";
}
i guess you should write:
Code:
else if(m==2&&days<=28)
{
cout<<"yout date is correct";
}
else
{
cout<<"invalid date";
}
. so the whole program without any compile time error is as :
Code:
#include <iostream>
using namespace std;
int calculate(void);
int main()
{
int a;
cout<<"enter the date(mm-dd-yy)";
cout<<calculate();
return 0;
}
int calculate()
{
int days,m,y;
cout<<"enter the date(mm-dd-yy)";
cin>>m>>days>>y;
if( m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m==12 )
{
days = 31;
}
else if( m == 4 || m == 6 || m == 9 || m == 11 )
{
days = 30;
}
else if( y % 4 == 0 && m == 2 )
{
days = 29;
}
else if( m == 2 && days <= 28 )
{
cout<<"yout date is correct";
}
else
{
cout<<"invalid date";
}
return 0;
}
but remember i think this code has some logic errors! so thats on you!
and once more again! , i just tried to omit the compile time errors! and i must say that there are some sever logic errors and also problems in your program! your program is not complete , is it!?
and i think its a good idea , to let a professional ( admin or other pros here) see this thread and guide you.
by the way someone verify i didnt screw up sth ( if did say sth wrong please tell me.):d