hello!
i would like to ask something about a program that i am trying to do. I wrote the program but i cant find where is my fault and doesnt check the right day for the february. I sent you my program, if anybody has something to suggest. The suggestion of the exercise doesnt recomment leap loop just only the m[]. Thank you in advance ......mp

#include <iostream>
using namespace std;

int get_date(int day,int month,int year);

void main(){
int day,year,month;

    cout<<"day: ";
    cin>>day;
    cout<<"month: ";
    cin>>month;
    cout<<"year: ";
    cin>>year;
    get_date(day,month,year);
}
    int get_date (int day,int month,int year){

    int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};

 if ((day>0 && day<31) && (month>0 && month<=12) && year>0)
 {
    if((year%4)==0) m[1]=29;
     if (day<=m[month-1])
     {  
         cout<<"H imerominia einai: "<<day<<"-"<<month<<"-"<<year;
         else 
            cout<<"wrong";
     cout<<endl;
      }  
 else
     cout<<"wrong";
     }
 return 0;

 ]

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You don't say anything about the output you're getting, but I can see a couple of problems.
In this line

if ((day>0 && day<31) && (month>0 && month<=12) && year>0)

you're not allowing a day of 31 to be accepted, so make it day<=31.
Also, regarding the Febuary problem, you're algorithm for detecting a leap year is too simple. ((year%4)==0) is a start, but you must go further because every hundred years (determined a leap year by ((year%4)==0), the extra day is not required. Then you must go further still because every 400 years (just omitted from being a leap year by the hundred year rule) the extra day is again required. It shouldn't be too hard Google some leap year algorithms.

This article has been dead for over six months. Start a new discussion instead.