Calculating Day of the Week

EDIT: Gah... sorry, just found the fmod function... sorry about the thread. Could a mod please delete this?



Okay, sorry about the massive amount of threads lately, I've taken up C++ again.

Anyways, I'm writing a function that takes a year, a month, a day, and the century and it is supposed to return what day of the week it falls on. Now I've got almost everything down, but I need to know one thing: How do I find the remainder of a division equation? The last step for calculating the day of the week is to divide the total you get by 7, and the remainder corresponds to a day of the week, but I can't for the life of me figure out how to do that. Here is the function:

(PS: The 'year' value is the last two digits of the year.)
(PPS: Don't ask about the function name, it's not important. :P)
[code=cpp]void DayOfTheWeekCJ( int year, int month, int day, int century )
{
//JANUARY = 1
//FEBURARY = 2
//MARCH = 3
//APRIL = 4
//MAY = 5
//JUNE = 6
//JULY = 7
//AUGUST = 8
//SEPTEMBER = 9
//OCTOBER = 10
//NOVEMBER = 11
//DECEMBER = 12
int dayoftheweek = year + (.25 * year) + day;

//MONTH VALUES *********************************************
if( month == '1' || month == '10' )
{
dayoftheweek = dayoftheweek + 1;
}
else if( month == '2' || month == '3' || month == '11' )
{
dayoftheweek = dayoftheweek + 4;
}
else if( month == '5' )
{
dayoftheweek = dayoftheweek + 2;
}
else if( month == '6' )
{
dayoftheweek = dayoftheweek + 5;
}
else if( month == '8' )
{
dayoftheweek = dayoftheweek + 3;
}
else if( month == '9' || month == '12' )
{
dayoftheweek = dayoftheweek + 6;
}
//END MONTH VALUES ****************************************



//CENTURY VALUES ******************************************
if( century == '18' )
{
dayoftheweek = dayoftheweek + 4;
}
else if( century == '19' )
{
dayoftheweek = dayoftheweek + 2;
}
else if( century == '21' )
{
dayoftheweek = dayoftheweek + 6;
}
//END CENTURY VALUES **************************************



//CALCULATE DAY *******************************************
dayoftheweek = dayoftheweek / 7;
//END CALCULATE DAY ***************************************
}[/code]


Any ideas on how to get the remainder?
Last edited on
Or you could just simply use the modulo operator (%)...
Topic archived. No new replies allowed.