Gregorian Date Checker

Hi, so I'm trying to write a bool function that determines whether a date is a Gregorian date or not. A date cannot be Gregorian if it is from September 13, 1752 or earlier. I'm not really sure how to structure a function that determines this, but this is what I have so far and apparently I'm doing something horribly wrong. Any help?
Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  bool isGregorianDate(int month, int day, int year) {
    if (((month <= 9) && (month >= 1)) && ((day <= 13) && (day >= 1)) && (year = 1752)) {
        return false;
    }
    else if (((month = 9) && ((day > 13) && (day <= 30)) && (year = 1752)) {
        return true;
    }
    else if (((month = 11) && ((day >= 1) && (day <= 30)) && (year = 1752)) {
        return true;
    }
    else if (((month = 10 || 12) && ((day >= 1) && (day <= 31)) && (year = 1752)) {
        return true;
    }
    else if (year < 1752) {
        return false;
    }
    else if (year > 1752) {
        return true;
    }
}
closed account (48T7M4Gy)
Try this, only partly tested but seems to work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

// true if >= September 13, 1752

bool isGregorianDate(int month, int day, int year)
{
    if (year < 1752)
        return false;
    
    if ( year == 1752 and month <= 8 )
        return false;

    if ( month == 9 and day < 13)
        return false;
    
    return true;
}

int main()
{
    std::cout << (isGregorianDate(9, 14, 1752)? "true":"false") << '\n';
    return 0;
}
closed account (48T7M4Gy)
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
#include <iostream>

// true if >= September 13, 1752

bool isGregorianDate(int month, int day, int year)
{
    if (year < 1752)
        return false;
    
    if ( year == 1752 and month < 9 )
        return false;
    
    if ( month == 9 and day < 13)
        return false;
    
    return true;
}

void test_a_date( int year, int month, int day)
{
    std::cout << (isGregorianDate(month, day, year)? "true":"false") << '\n';
}


int main()
{
    test_a_date(1751,12,30);
    
    test_a_date(1752,1,1);
    test_a_date(1752,8,30);
    test_a_date(1752,9,12);
    test_a_date(1752,9,13);
    test_a_date(1752,9,14);
    test_a_date(1752,10,1);
    test_a_date(1752,12,30);
    
    test_a_date(1753,9,13);
    return 0;
}


false
false
false
false
true
true
true
true
true
Program ended with exit code: 0
Last edited on
I really appreciate it, man! I'll see how it works with my project.
Topic archived. No new replies allowed.