The assignment is the following: write a program that determines the day of the week for a given date by using the julian day number. this is the number of days that have elapsed since January 1, 4713 BC. The JDN date can calculate the day of week by this formula  DayofWeek = (JDN +1) % 7 The result is in the range of 0 to 6 with 0 as Sunday. How is the JDN computed? If using the Gregorian calendar (later than October 15, 1582) then compute intRes1 with the following formula or let intRes1 be zero.
intRes1 = 2  year / 100 + year / 400
second result is computed as: intRes2 = int(365.25 * year)
third value is computed as: intRes3 = int(30.6001 * (month + 1))
JDN is computed as JDN = intRes1 + intRes2 + intRes3 + day + 1720994.5
Formulas require nine significant digits;using integer type long and floatingpoint type double. should prompt for input of date and label the output.
Here's my code for a problem I'm working on for class. I can't get it to work and don't know what I'm missing. Any advice would be great.
double intRes1;
long intRes2;
long intRes3;
double temp;
//Gregorian calendar test date
if(month <= 10 && day <=15 && year <=1582)
intRes1 = 0;
else
intRes1 = 2  (year/100) + (year/400);
//JDN calculation
intRes2 = long(365.25 * year);
intRes3 = long(30.6001 * (month+1));
jdn = intRes1 + intRes2 + intRes3 + day + 1720994.5;
temp = intRes1 + intRes2 + intRes3 + day + 1720994.5;
if (temp  jdn >= .5)
jdn = jdn + 1;
Day of Week
Page 1 of 15 Replies  12842 Views  Last Post: 30 October 2006  12:16 AM
Replies To: Day of Week
#2
Re: Day of Week
Posted 29 October 2006  05:35 PM
Can you specify the problem you are encountering, along with any error messages you are receiving? Also, this problem looks quite similar to another on the site...perhaps taking a look might guide you as well:
http://forums.dreami...wtopic20136.htm
http://forums.dreami...wtopic20136.htm
#3
Re: Day of Week
Posted 29 October 2006  07:16 PM
#include <string> #include <cmath> #include <iostream> #include <iomanip> using namespace std; //Determine Function Prototypes void DetermineWeekDay(float, float, float, int, int, int, int, int&); int main() { //Input variables float day; float month; float year; int DayofWeek; long int intRes1 = 0; long int intRes2 = 0; long int intRes3 = 0; long int JDN = 0; bool dataOK = false; do { cout << "Please enter the month"; cin >> month; cout << "Please enter the week day:"; cin >> day; cout << "Please enter the year:"; cin >> year; if (month <= 10 && day <= 15 && year <= 1582) { intRes1 = 0; } else { cout << "year / 100 = " << year / 100 << ", year / 400 = " << year / 400 << endl; intRes1 = 2  (year / 100) + (year / 400); } cout << "intRes1 = " << intRes1 << endl; { //DoCalculation } } while (dataOK== false); DetermineWeekDay (day, month, JDN, year, intRes1, intRes2, intRes3, DayofWeek); cin.get(), cin.get(); return 0; } void DetermineWeekDay (float day,float month,float year,long int JDN, long int intRes1, long int intRes2,long int intRes3,int& DayofWeek) { //Precondition: The day of the week must be entered. //Postcondition: The user must enter information correctly. intRes1 = (2year / 100 + year / 400); intRes2 = int(365.25 * year); intRes3 = int(30.6001 * (month + 1)); JDN = ((intRes1 + intRes2 + intRes3 + day) + 1720944.5); temp = intRes1 + intRes2 + intRes3 + day + 1720994.5; if (temp  JDN>= .5) DayofWeek = ((JDN + 1) % 7)+1; cout << " The day of the week " << " for " << month << day << year << "is" << DayofWeek; if (DayofWeek == 0) cout << "Sunday"; else if (DayofWeek == 1) cout << "Monday"; else if (DayofWeek == 2) cout << "Tuesday"; else if (DayofWeek == 3) cout << "Wednesday"; else if (DayofWeek == 4) cout << "Thursday"; else if (DayofWeek == 5) cout << "Friday"; else if (DayofWeek == 6) cout << "Saturday"; cout << endl; return;
Here are my errors and I don't know what to fix. The problem you gave me is the same one so it looks like someone else is having problems with it too.
warning C4244: '=' : conversion from 'float' to 'long', possible loss of data line 43
warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data line 56
warning C4244: 'argument' : conversion from 'long' to 'float', possible loss of data line 56
warning C4244: '=' : conversion from 'float' to 'long', possible loss of data line 69
warning C4244: '=' : conversion from 'double' to 'long', possible loss of data line 72
): error C2065: 'temp' : undeclared identifier line 73
error C3861: 'temp': identifier not found, even with argumentdependent lookup line 74
#4
Re: Day of Week
Posted 29 October 2006  07:25 PM
You are getting the error becasue you are using a variable named temp in your function, but have never declared or instantiated such a variable.
The others are warnings becasue you are assigning values of one variable type to another variable type.
The others are warnings becasue you are assigning values of one variable type to another variable type.
#5
Re: Day of Week
Posted 29 October 2006  08:20 PM
#include <string>
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;
//Determine Function Prototypes
void DetermineWeekDay(float, float, float, int, int, int, int, int&);
int main()
{
//Input variables
float day;
float month;
float year;
int DayofWeek;
int intRes1 = 0;
int intRes2 = 0;
int intRes3 = 0;
int JDN = 0;
bool dataOK = false;
do
{
cout << "Please enter the month";
cin >> month;
cout << "Please enter the week day:";
cin >> day;
cout << "Please enter the year:";
cin >> year;
if (month<13)
dataOK = true;
else
cout << "Please enter a number less than 13 for the month: "
<< endl;
if (day<32);
else
cout << "Please enter a number less than 32 for the day:"
<< endl;
if((year>1582)  //Picks any years from Gregorian Calendar greater than 1582
(month>10) && (year==1582)  //Picks months greater than 10 in 1582 from Gregorian Calendar
(month== 10) && (day>15) && (year== 1582)) // Picks only month 10 and any days over 15 in year 1582 from Gregorian Calendar
{
// do calculation
}
} while (dataOK== false);
DetermineWeekDay (day, month, JDN, year, intRes1, intRes2, intRes3, DayofWeek);
cin.get(), cin.get();
return 0;
}
void DetermineWeekDay (float day,float month,float year, int JDN, int intRes1,
int intRes2, int intRes3,int& DayofWeek)
{
//Precondition: The day of the week must be entered.
//Postcondition: The user must enter information correctly.
intRes1 = (2year / 100 + year / 400);
intRes2 = int(365.25 * year);
intRes3 = int(30.6001 * (month + 1));
JDN = ((intRes1 + intRes2 + intRes3 + day) + 1720944.5);
DayofWeek = ((JDN + 3) % 7);
cout << " The day of the week " << " for "
<< month << day << year << "is" << DayofWeek;
if (DayofWeek == 0)
cout << "Sunday";
else if (DayofWeek == 1)
cout << "Monday";
else if (DayofWeek == 2)
cout << "Tuesday";
else if (DayofWeek == 3)
cout << "Wednesday";
else if (DayofWeek == 4)
cout << "Thursday";
else if (DayofWeek == 5)
cout << "Friday";
else if (DayofWeek == 6)
cout << "Saturday";
cout << endl;
return;
}
Ok. I took that out completely. Can you help me with these errors, please? I need to turn my assignment in in several hours.
fatal error LNK1201: error writing to program database check for insufficient disk space, invalid path, or insufficient privilege
(58): warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
(58): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
(71): warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
(74): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;
//Determine Function Prototypes
void DetermineWeekDay(float, float, float, int, int, int, int, int&);
int main()
{
//Input variables
float day;
float month;
float year;
int DayofWeek;
int intRes1 = 0;
int intRes2 = 0;
int intRes3 = 0;
int JDN = 0;
bool dataOK = false;
do
{
cout << "Please enter the month";
cin >> month;
cout << "Please enter the week day:";
cin >> day;
cout << "Please enter the year:";
cin >> year;
if (month<13)
dataOK = true;
else
cout << "Please enter a number less than 13 for the month: "
<< endl;
if (day<32);
else
cout << "Please enter a number less than 32 for the day:"
<< endl;
if((year>1582)  //Picks any years from Gregorian Calendar greater than 1582
(month>10) && (year==1582)  //Picks months greater than 10 in 1582 from Gregorian Calendar
(month== 10) && (day>15) && (year== 1582)) // Picks only month 10 and any days over 15 in year 1582 from Gregorian Calendar
{
// do calculation
}
} while (dataOK== false);
DetermineWeekDay (day, month, JDN, year, intRes1, intRes2, intRes3, DayofWeek);
cin.get(), cin.get();
return 0;
}
void DetermineWeekDay (float day,float month,float year, int JDN, int intRes1,
int intRes2, int intRes3,int& DayofWeek)
{
//Precondition: The day of the week must be entered.
//Postcondition: The user must enter information correctly.
intRes1 = (2year / 100 + year / 400);
intRes2 = int(365.25 * year);
intRes3 = int(30.6001 * (month + 1));
JDN = ((intRes1 + intRes2 + intRes3 + day) + 1720944.5);
DayofWeek = ((JDN + 3) % 7);
cout << " The day of the week " << " for "
<< month << day << year << "is" << DayofWeek;
if (DayofWeek == 0)
cout << "Sunday";
else if (DayofWeek == 1)
cout << "Monday";
else if (DayofWeek == 2)
cout << "Tuesday";
else if (DayofWeek == 3)
cout << "Wednesday";
else if (DayofWeek == 4)
cout << "Thursday";
else if (DayofWeek == 5)
cout << "Friday";
else if (DayofWeek == 6)
cout << "Saturday";
cout << endl;
return;
}
Ok. I took that out completely. Can you help me with these errors, please? I need to turn my assignment in in several hours.
fatal error LNK1201: error writing to program database check for insufficient disk space, invalid path, or insufficient privilege
(58): warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
(58): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
(71): warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
(74): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
#6
Re: Day of Week
Posted 30 October 2006  12:16 AM
hmapes, on 29 Oct, 2006  08:20 PM, said:
fatal error LNK1201: error writing to program database check for insufficient disk space, invalid path, or insufficient privilege
(58): warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
(58): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
(71): warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
(74): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
(58): warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
(58): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
(71): warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
(74): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
The first problem you need to fix is the fatal error...
Is there any possibility you are using a floppy drive to store your code?
Page 1 of 1
