// Calendar.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//function prototypes
void WeekDay(float, float, int, int, int, int, int, int&);
int main()
{
float day;
float month;
int year;
int DayofWeek;
int intRes1 = 0;
int intRes2 = 0;
int intRes3 = 0;
int JDN = 0;
bool dataareOK = false;
do
{
cout << "What is the month? (mm) ";
cin >> month;
cout << "What is the day? (dd) ";
cin >> day;
cout << "What is the year? (yyyy) ";
cin >> year;
if (month < 13)
dataareOK = true;
else
cout << "You have entered an invalid month (1-12 only)"
<< endl;
if ( day<32);
else
cout << "You have entered an invalid day (1-31 only)"
<< endl;
if((year > 1582) || // years greater than 1582
(month > 10) && (year == 1582) || // months greater than 10 in 1582
(month == 10) && (day > 15) && (year == 1582)) // Month is greater than 10, day is greater than 15 in the year of 1582
{
}
} while (dataareOK == false);
WeekDay (day, month, JDN, year, intRes1, intRes2, intRes3, DayofWeek);
cin.get();
return 0;
}
void WeekDay(float day, float month, int year, int JDN,int intRes1,
int intRes2, int intRes3, int& DayofWeek )
{
//Conditions
intRes1 = (2- year /100 + year / 400);
intRes2 = int(365.25 * year);
intRes3 = int(30.6001 * (month + 1));
JDN = ((intRes1 + intRes2 + intRes3 + day) + 1720944.5);
DayofWeek = ((JDN + 1) % 7);
cout << "\nThe day of the week " << "for "
<< month <<"/"<< day <<"/"<< year << " is" << DayofWeek<<endl;
if (DayofWeek == 0)
cout << "Sunday";
else if (DayofWeek == 1) //Nested If
cout << "Monday";
else if (DayofWeek == 2) //Nested If
cout << "Tuesday";
else if (DayofWeek == 3) //Nested If
cout << "Wednesday";
else if (DayofWeek == 4) //Nested If
cout << "Thursday";
else if (DayofWeek == 5) //Nested If
cout << "Friday";
else if (DayofWeek == 6) //Nested If
cout << "Saturday";
cout << endl;
return;
}
Problem is output: MM/DD/0 <-- Year does not print out right... something to do with the
order of 'JDN' ?
Also, the 'blah blah is' shows the number after it....some kind of problem in the nested IF
Thanks for the help.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//function prototypes
void WeekDay(float, float, int, int, int, int, int, int&);
int main()
{
float day;
float month;
int year;
int DayofWeek;
int intRes1 = 0;
int intRes2 = 0;
int intRes3 = 0;
int JDN = 0;
bool dataareOK = false;
do
{
cout << "What is the month? (mm) ";
cin >> month;
cout << "What is the day? (dd) ";
cin >> day;
cout << "What is the year? (yyyy) ";
cin >> year;
if (month < 13)
dataareOK = true;
else
cout << "You have entered an invalid month (1-12 only)"
<< endl;
if ( day<32);
else
cout << "You have entered an invalid day (1-31 only)"
<< endl;
if((year > 1582) || // years greater than 1582
(month > 10) && (year == 1582) || // months greater than 10 in 1582
(month == 10) && (day > 15) && (year == 1582)) // Month is greater than 10, day is greater than 15 in the year of 1582
{
}
} while (dataareOK == false);
WeekDay (day, month, JDN, year, intRes1, intRes2, intRes3, DayofWeek);
cin.get();
return 0;
}
void WeekDay(float day, float month, int year, int JDN,int intRes1,
int intRes2, int intRes3, int& DayofWeek )
{
//Conditions
intRes1 = (2- year /100 + year / 400);
intRes2 = int(365.25 * year);
intRes3 = int(30.6001 * (month + 1));
JDN = ((intRes1 + intRes2 + intRes3 + day) + 1720944.5);
DayofWeek = ((JDN + 1) % 7);
cout << "\nThe day of the week " << "for "
<< month <<"/"<< day <<"/"<< year << " is" << DayofWeek<<endl;
if (DayofWeek == 0)
cout << "Sunday";
else if (DayofWeek == 1) //Nested If
cout << "Monday";
else if (DayofWeek == 2) //Nested If
cout << "Tuesday";
else if (DayofWeek == 3) //Nested If
cout << "Wednesday";
else if (DayofWeek == 4) //Nested If
cout << "Thursday";
else if (DayofWeek == 5) //Nested If
cout << "Friday";
else if (DayofWeek == 6) //Nested If
cout << "Saturday";
cout << endl;
return;
}
Problem is output: MM/DD/0 <-- Year does not print out right... something to do with the
order of 'JDN' ?
Also, the 'blah blah is' shows the number after it....some kind of problem in the nested IF
Thanks for the help.