|
-
October 23rd, 2009, 06:34 PM
#1
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.
-
October 24th, 2009, 08:01 AM
#2
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;
-
October 28th, 2009, 07:45 AM
#3
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.
-
October 28th, 2009, 03:07 PM
#4
Re: Zeller's Congruence
 Originally Posted by BobS0327
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?
-
October 28th, 2009, 04:43 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|