Question #38080

i want a program that compute and display the next of the specific date in Gregorian calender.The date should be entered day/month/year.An invalid date should be handled properly.

Expert's answer

Answer on Question#38080- Programming - C++

1. I want a program that compute and display the next of the specific date in Gregorian calendar. The date should be entered day/month/year. An invalid date should be handled properly.

Solution.

#include <iostream>
#include <time.h>
using namespace std;
struct struct_date
{
    char day;
    char month;
    short year;
};
int what_day(const struct struct_date * const date);
int main(int argc, char* argv[])
{
    int a=0;
    cout<<"Enter date day/month/year: "<<endl;
    cin>>a; sdate->day=a;
    cin>>a; sdate->month=a;
    cin>>a; sdate->year=a;
    if(a>31) {cout<<"Invalid date."<<endl; system("pause"); return 0;}
    if(a>12) {cout<<"Invalid date."<<endl; system("pause"); return 0;}
    if(a>9999) {cout<<"Invalid date."<<endl; system("pause"); return 0;}
    cout<<endl<<"Result: ";
    switch(what_day(sdate))
    {
        case 0: cout<<"Monday"; break;
        case 1: cout<<"Tuesday"; break;
        case 2: cout<<"Wednesday"; break;
        case 3: cout<<"Thursday"; break;
        case 4: cout<<"Friday"; break;
        case 5: cout<<"Saturday"; break;
        case 6: cout<<"Sunday"; break;
    }
    cout<<endl;
    system("pause");
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS