CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2009
    Posts
    7

    Zeller's Congruence

    The error i keep getting is

    27 ..\p2\dayCount.cpp expected `)' before numeric constant

    Anyone able to give me some insight into this?

    #include <iostream>
    #include <cmath>
    using namespace std;

    int main(){
    //user input
    int q; // q = day of the month (1-31)
    int m; // m = month (3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, 12 = December, 13 = Janurary, 14 = February)
    int y; // Year ####
    //calculated values
    int k; // k = year of the century
    int j; // j = century (For example, in 1995 the century would be 19, even though it was the 20th century.)
    //After complet Calculations
    int h; // h = day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thrusday, 6 = Friday)

    cout << "Enter the Day of the Month (1-31): ";
    cin >> q;
    cout << endl;
    cout << "Enter the Month: " << endl;
    cout << "3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, 12 = December, 13 = Janurary, 14 = February" << endl;
    cin >> m;
    cout << endl;
    cout << "Enter the Year: ";
    cin >> y;
    cout << endl;

    h = ( q + floor( ((m+1)26) / 10 ) + y + floor(y/4) + 6 * floor(y/100) + floor(y/400)) % 7;

    cout << h;

    system("pause");
    return 0;
    }
    Last edited by Jaxyral; November 2nd, 2009 at 03:21 PM.

  2. #2
    Join Date
    Apr 2004
    Posts
    102

    Re: Zeller's Congruence

    Looks like the problem is ((m+1)26). Possibly need a arithmetic operator between the right paren and 26???

    Code:
    h = ( q + floor( ((m+1)26) / 10 ) + y + floor(y/4) + 6 * floor(y/100) + floor(y/400)) % 7;

  3. #3
    Join Date
    Apr 2007
    Location
    Mars NASA Station
    Posts
    1,436

    Re: Zeller's Congruence

    AFAIK, we does not need any formula to calculate day of week.

    You can use computation logic with the help of array.
    Thanks for your help.

  4. #4
    Join Date
    Apr 2004
    Posts
    102

    Re: Zeller's Congruence

    Quote Originally Posted by BobS0327 View Post
    Looks like the problem is ((m+1)26). Possibly need a arithmetic operator between the right paren and 26???

    Code:
    h = ( q + floor( ((m+1)26) / 10 ) + y + floor(y/4) + 6 * floor(y/100) + floor(y/400)) % 7;
    All the variables are already ints so using the floor() function is redundant. You also might want to look into putting some error guards in against invalid dates like February 29 in a non-leap year, or September 31.

    Out of curiosity...what is the reason behind the non-standard numeric assignment of the weekdays and months?

  5. #5
    Join Date
    Apr 2004
    Posts
    102

    Re: Zeller's Congruence

    C FAQ Zeller Conguence

    Code:
    #include <iostream>
    #include <cmath>
    #include <stdio.h>
    using namespace std;
    
    int main(){
        //user input
        int q; // q = day of the month (1-31)
        int m; // m = month (3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, 12 = December, 13 = Janurary, 14 = February)
        int y; // Year ####
        //calculated values
        int k; // k = year of the century, last two digits.  For example, 2009 would be 09
        int j; // j = century (For example, in 1995 the century would be 19, even though it was the 20th century.)
        //After complet Calculations
        int h; // h = day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, 3 = Tuesday, 4 = Wednesday, 5 = Thrusday, 6 = Friday)
    
        cout << "Enter the Day of the Month (1-31): "; 
        cin >> q; 
        cout << endl;
        cout << "Enter the Month: " << endl;
        cout << "3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, 12 = December, 13 = Janurary, 14 = February" << endl;
        cin >> m; 
        cout << endl;
        cout << "Enter the Year: "; 
        cin >> y;
        cout << endl;
        j = y /100;
        k = y % 100;
        h = (q + 26 * (m + 1) / 10 + k + k/4 + j/4 + 5*j) % 7;
        //  h = ( q + floor( ((m+1)26) / 10 ) + y + floor(y/4) + 6 * floor(y/100) + floor(y/400)) % 7; 
        cout << h;
        system("pause");
        return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured