C++ Zeller\'s congruence is an algorithm developed by Christian Zeller to calcul
ID: 3551816 • Letter: C
Question
C++
Zeller's congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h = (q + 26(m + 1/10 + k + k/4 + j/4 + 5j)% 7 where h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). q is the day of the month. m is the month (3: March, 4: April,...,12: December). January and February are counted as months 13 and 14 of the previous year. j is the century (i.e., year/100). k is the year of the century (i.e., year % 100). Note that the division in the formula performs an integer division. Write a program that prompts the user to enter a year, month, and day of the month, and displays the name of the day of the week. Here are some sample runs:Explanation / Answer
#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;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.