Join 136,145 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,081 people online right now. Registration is fast and FREE... Join Now!
I need to write a program to convert a user given input date say 15/3/2006 and find out what day of the week it was. I tried to code but I am still facing difficulties. lets say there can be any dates between 2005 and 2020.I am not being able to figure how to convert teh date.Could someone please help????
well you could figure out todays value, using System.DateTime.Now() then using an array of the days of the week. Then figure out the difference in days from today and the day entered, modulo it to get the remainder and add that to the value of today in the array, (watching to cycle around should the value be larger than 6, since the array will be 0-6 values) and this should be the day.
I need to write a program to convert a user given input date say 15/3/2006 and find out what day of the week it was. I tried to code but I am still facing difficulties. lets say there can be any dates between 2005 and 2020.I am not being able to figure how to convert teh date.Could someone please help????
if i understand what u mean exactly i think this is the code;
CODE
#include<stdio.h> int leap (int year);
int main (void){ int month,day,year,dm,dn,leap;
printf("enter the month:"); scanf("%d",&month);
printf("enter the day:"); scanf("%d",&day);
printf("enter the year:"); scanf("%d",&year);
if (leap==0) { if(month==1) dm=0; if(month==2) dm=31;
Just one question., this gives me the day number, so if i want the weekday(like sunday, monday), taking the remainder of dn%7 should give me the weekday (if sunday=0,monday=1)right?
QUOTE(salmalita @ 10 Apr, 2007 - 07:45 PM)
QUOTE(new2programs @ 10 Apr, 2007 - 02:45 PM)
Hi,
I need to write a program to convert a user given input date say 15/3/2006 and find out what day of the week it was. I tried to code but I am still facing difficulties. lets say there can be any dates between 2005 and 2020.I am not being able to figure how to convert teh date.Could someone please help????
if i understand what u mean exactly i think this is the code;
CODE
#include<stdio.h> int leap (int year);
int main (void){ int month,day,year,dm,dn,leap;
printf("enter the month:"); scanf("%d",&month);
printf("enter the day:"); scanf("%d",&day);
printf("enter the year:"); scanf("%d",&year);
if (leap==0) { if(month==1) dm=0; if(month==2) dm=31;
// determine day stringstream buffer2(data.substr(3,5)); int dy = 0; buffer2 >> dy;
// determine year stringstream buffer3(data.substr(6,8)); int yr = 0; buffer3 >> yr;
// convert year into a string stringstream ss; ss << yr; ss.str();
string result = ss.str();
// determine the lenght of the string string::size_type len; len = result.size();
switch(len) { case 0: result.insert(0,"2000"); break; case 1: result.insert(0,"200"); break; case 2: result.insert(0,"20"); break; }
// convert the string back to an integer stringstream buffer4(result); int normalYr = 0; buffer4 >> normalYr;
if(mn <= 0 && mn > 12) // validate the month { month = 1; // invalid month set to 1 cout << "Invalid month (" << month << ") set to 1.\n"; } // end else else { month = mn; } year = normalYr; day = checkDay(dy); // validate the day and check for a leap year }