Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,330 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,827 people online right now. Registration is fast and FREE... Join Now!




PLEASE HELP WITH THIS LOGIC.

 
Reply to this topicStart new topic

PLEASE HELP WITH THIS LOGIC.

sash007
16 May, 2008 - 11:29 PM
Post #1

New D.I.C Head
*

Joined: 16 May, 2008
Posts: 2

A programme in C++ that if date is input it tells day?

For example
Enter Date : 1-01-1985
The day is 'Monday'

Enter Date : 2-01-1985
The day is 'Tuesday'

Restriictions are using If-else, switch,operators(/,%,*,+,-) while loop.logical operations(&& || )
Please write the programme or Explain the logic
It starts like this.
if (year%4==0)
"it is leap year"
Then what?????
PLEASE HELP.
THIS IS MY FINAL DESTINATION.If no answer from here. I won't find it how to do!!!
I have only one day!!!!!!!!!!
PLEASE!PLEASE!!!!!!!!!
PLEASE WRITE CALCULATIONS AND LOGIC.
Thanx.

User is offlineProfile CardPM
+Quote Post

KYA
RE: PLEASE HELP WITH THIS LOGIC.
16 May, 2008 - 11:53 PM
Post #2

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 4,821



Thanked: 95 times
Dream Kudos: 1200
My Contributions
Have it calculate the # of days from a certain date: Jan, 1 1900 works well for this purpose. Have it account for leap years. The modulo of that number from seven will give you the start day of that month and you can find the day from there.
User is online!Profile CardPM
+Quote Post

sash007
RE: PLEASE HELP WITH THIS LOGIC.
17 May, 2008 - 03:52 AM
Post #3

New D.I.C Head
*

Joined: 16 May, 2008
Posts: 2

this is the code i made?
Please check and remove errors.
Thanx

I took formula from this site.
http://mathforum.org/dr.math/faq/faq.calendar.html


#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int d,m,y1,y2,f,day,y;
char v='/',v2='-';
cout<<"\n\n\nEnter the date please in this format eg(25/06/20-08) ";
cin>>d>>v>>m>>v>>y1>>v2>>y2;
y=y2-1;
f=d+(((13*m)-1)/5)+y+(y/4)+(y1/4)-2*y1;
day=f%7;
if(day<0)
{
day2=(-1*day)+(-1*day);


if(day==0)
cout<<" THE DAY IS **** SUNDAY **** ";
else
if(day==1)
cout<<" THE DAY IS **** MONDAY **** ";
else
if(day==2)
cout<<" THE DAY IS **** TEUSDAY **** ";
else
if(day==3)
cout<<" THE DAY IS **** WEDNEDAY **** ";
else
if(day==4)
cout<<" THE DAY IS **** THURSDAY **** ";
else
if(day==5)
cout<<" THE DAY IS **** FRIDAY **** ";
else
if(day==6)
cout<<" THE DAY IS **** SATURDAY **** ";

/*else
if(day<0)
{
day2=(-1*day)+(-1*day);
if(day2==0)
cout<<" THE DAY IS **** SUNDAY **** ";
else
if(day2==1)
cout<<" THE DAY IS **** MONDAY **** ";
else
if(day2==2)
cout<<" THE DAY IS **** TEUSDAY **** ";
else
if(day2==3)
cout<<" THE DAY IS **** WEDNEDAY **** ";
else
if(day2==4)
cout<<" THE DAY IS **** THURSDAY **** ";
else
if(day2==5)
cout<<" THE DAY IS **** FRIDAY **** ";
else
if(day2==6)
cout<<" THE DAY IS **** SATURDAY **** ";*/


getch();
}

User is offlineProfile CardPM
+Quote Post

gabehabe
RE: PLEASE HELP WITH THIS LOGIC.
17 May, 2008 - 04:03 AM
Post #4

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,526



Thanked: 98 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
Here is your code, cleaned up (I haven't tested it, but it should compile)
cpp
#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
system ("cls");
int d,m,y1,y2,f,day,y;
char v='/',v2='-';
cout<<"\n\n\nEnter the date please in this format eg(25/06/20-08) ";
cin>>d>>v>>m>>v>>y1>>v2>>y2;
y=y2-1;
f=d+(((13*m)-1)/5)+y+(y/4)+(y1/4)-2*y1;
day=f%7;

if(day<0)
day=(-1*day)+(-1*day);


if(day==0)
cout<<" THE DAY IS **** SUNDAY **** ";

else if(day==1)
cout<<" THE DAY IS **** MONDAY **** ";

else if(day==2)
cout<<" THE DAY IS **** TEUSDAY **** ";

else if(day==3)
cout<<" THE DAY IS **** WEDNEDAY **** ";

else if(day==4)
cout<<" THE DAY IS **** THURSDAY **** ";

else if(day==5)
cout<<" THE DAY IS **** FRIDAY **** ";

else if(day==6)
cout<<" THE DAY IS **** SATURDAY **** ";

getch();
}

Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

skater_00
RE: PLEASE HELP WITH THIS LOGIC.
17 May, 2008 - 02:12 PM
Post #5

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
Yes, it compiles. Compiler only says that it would be better to use _getch().

This post has been edited by skater_00: 17 May, 2008 - 03:31 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 07:49AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month