day in week help!

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1944 Views - Last Post: 13 February 2008 - 06:43 PM Rate Topic: -----

#1 ghost97cobra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-February 08

day in week help!

Posted 13 February 2008 - 11:55 AM

ight guys lost again! man i cant wait till i get the swing of this stuff! thanks to everyone that has been helping me.

I need to create a function called day_of_week that returns an int in the range of [0..6] 0 cout's sunday 1 monday etc. i have to use the modified zeller's rule.
day_in_week = [ d + (13 * m2-1)/ 5 + m2 + m2 / 4 + c2 / 4 * 5 * c2 ] % 7
so what i have wrote so far is
void day_in_week ()	
		{   
		  cout << "\n Enter the Year:";
		  int year;
		  cin >> year;
		  cout << "\n Enter the month:";
		  int month;
		  cin >> month;
		  cout << "\n Enter the day:";
		  int days;
		  cint >> days;  
		  int m2 = month-2;
		  int y2 = year;
		  

				  if ( m < 3)
				{ 
				  m2 += 12;
				  y2 -= 1;
				} 
		   int c2 = y2 / 100;
		   int d2 = y2 % 100;
		 }


and my whole program is
 
#include <iostream>
  
using namespace std;
	 
void menu ();		
void wrt_menu ();	
void test_leap_year ();
bool deal_with_it ( char event );
bool is_leap_year ( int year );
void wait_up ();
void test_days_in_month ();
int  days_in_month ( int year, int month );
int  year;
int  month;
int  days;
bool is_valid_date ( int year, int month, int days );
void test_valid_date ();
void day_of_year ();
int  is_day_of_year ( int year, int month, int days );
void day_in_week ();
	 
  int main ()
	{
	  cout << "\n\n Project 2 the date project \n\n";
	  menu (); 
	  cout << "\n\n End of Project 2";
	  return EXIT_SUCCESS;
	}		   
  
  void menu ()
   {
	 bool done = false;
	 char event;
	 while ( ! done )
	 {	
	  wrt_menu();
	  cin >> event;
	  done = deal_with_it ( event );
	 }	
   }	  
	   
  void wrt_menu ()
   {	  
		  
	 cout << " Date Program					 Kenneth Eddy\n\n";
	 cout << " L: Test for leap year.\n";
	 cout << " M: Days in a month.\n";
	 cout << " V: valid date.\n";
	 cout << " Y: day in Year.\n";	
	 cout << " W: day in Week.\n";
	 cout << " E: Expanded date.\n";
	 cout << " Q: Quit.\n\n\n";
	 cout << " Enter your choice [ L, M, V, Y, W, E, Q ] :";
	
   } 
	 
  bool deal_with_it ( char event )
   {	  
	switch ( event )
	 {
	   case 'l':
	   case 'L':
		  test_leap_year ();
		  break;
	   case 'm':  
	   case 'M':
		  test_days_in_month ();
		  break;
	   case 'v':
	   case 'V':
		  test_valid_date ();	
		  break;
	   case 'y':
	   case 'Y':
		  day_of_year ();
	   case 'q':
	   case 'Q':
		 return true;
		 break;
	 } 
	   return false;
   }
	  
  void wait_up ()
   {   
	cout << "\n Enter any key to continue:";
	char fake;  
	cin >> fake;  
   }   
		  
  void test_leap_year ()
   {   
	cout << " Test for Leap year\n";
	cout << " \n Enter a year \n";
	int year;   
	cin >> year;
	  if ( is_leap_year(year))
		{ 
		  cout <<"\n\n"<< year << " is a leap year";
		}
		 else
		{
		  cout << "\n\n" << year << " is not a leap year";
		}
	   wait_up ();
	} 
  
   bool is_leap_year ( int year )
	 {
	  if ( year % 400 == 0 ) return true;
	  if ( year % 100 == 0 ) return false;
	  if ( year % 4   == 0 ) return true;
							 return false;
	 }
  
   void test_days_in_month ()	 
	{
	  cout << "\ndays in month test\n";
	  cout << "\n Enter a year";
	  int year;
	  cin >> year;
	  cout << "\n Enter a number for a month 1 = jan etc. to find the days in the month:\n";
	  int month;
	  cin >> month;
	  int days = days_in_month (year,month );
	  cout <<"\n\n year:" << year << "\nmonth:\n" << month;
	  cout << "\nhas" << days << "days";
	  
	}
   
   int days_in_month ( int year, int month )
	 {
	  switch ( month )
	   { 
		case 1 :			 
		case 3 :
		case 5 :
		case 7 :
		case 8 :
		case 10 :
		case 12 :
		   return 31;
		   break;
		case 4 :  
		case 6 :
		case 9 :
		case 11 :  
		   return 30;
		   break;
		 case 2 :
			if (is_leap_year(year))
			 {
			   return 29;
			 }
			   else {
			   return 28;
			   }
		 break;			  
		 cout << "default";
		 break; 
		 }
	  } 
		
bool is_valid_date ( int year, int month, int days )
  {		
   if ( month < 1 )  return false;
   if ( month > 12 ) return false;
   if ( days < 1 )  return false;
   if ( days > days_in_month ( year, month )) return false;
										  return true;
		   
   }	   
		 
void test_valid_date ()
  {		  
	 cout << "\n Enter a year:";
	 int year;
	 cin >> year;	
	 cout << "\n Enter a month:";
	 int month; 
	 cin >> month;		   
	 cout << "\n Enter a day:";
	 int days;  
	 cin >> days;
	   if ( is_valid_date ( year, month, days ))
		{
		  cout << year << month << days << " Is a Valid date ";
		}  
		else {
			   cout << "\n" << year << month << days << "Is not a valid date";
			 } 
   
  }									   
		   
int  is_day_of_year ( int year, int month, int days )
		{
		  switch (month)
			{
				case 1 : 
				  return days;
				  break;
				case 2 : 
				  return 31 + days;
				  break;	 
				case 3 : 
				  if (is_leap_year(year))
					{
					  return 60 + days;
					} else{
					 return 59 + days;
					}
					 break;
				case 4 :
				   if (is_leap_year(year))
					{
					 return 91 + days;	
					} else{
					 return 90 + days;
					}
					 break;
				case 5 :
					if (is_leap_year(year))
					{
					 return 121 + days;
					} else{
					 return 120 + days;
					}		
					 break;
				case 6 :
					  if (is_leap_year(year))
					{
					 return 152 + days;
					} else{ 
					 return 151 + days;
					}
					 break;
				case 7 :
					   if (is_leap_year(year))
					{
					 return 182 + days;
					} else{ 
					 return 181 + days;
					}
					 break;
				case 8 :
					   if (is_leap_year(year))
					{
					 return 213 + days;
					} else{ 
					 return 212 + days;
					}
					 break;
				case 9 :
					if (is_leap_year(year))
					{
					 return 244 + days;
					} else{ 
					 return 243 + days;
					}
					 break;
				case 10 : 
					   if (is_leap_year(year))
					{
					 return 274 + days;
					} else{ 
					 return 273 + days;
					}
					 break;
				case 11 : 
					   if (is_leap_year(year))
					{
					 return 305 + days;
					} else{ 
					 return 304 + days;
					}
					 break;
				case 12 : 
						 if (is_leap_year(year))
					{
					 return 336 + days;
					} else{ 
					 return 335 + days;
					}
					 break;
				}	  
			  }	 
					 
void day_of_year () 
		{			
		  cout << "\n Enter a year";
		  int year;  
		  cin >> year;	
		  cout << "\n Ente a month:";
		  int month; 
		  cin >> month;
		  cout << "\n Enter a day";
		  int days;  
		  cin >> days;
		  int day =  is_day_of_year ( year, month, days );
			  if ( is_valid_date ( year, month, days ))
		  {			  
			cout << "\nThe day in year is:" << day;
		  }else{	 
		   cout << "\n Invalid date!";
			  }	  
					 
		 }		   
void day_in_week ()	
		{   
		  cout << "\n Enter the Year:";
		  int year;
		  cin >> year;
		  cout << "\n Enter the month:";
		  int month;
		  cin >> month;
		  cout << "\n Enter the day:";
		  int days;
		  cint >> days;  
		  int m2 = month-2;
		  int y2 = year;
		  

				  if ( m < 3)
				{ 
				  m2 += 12;
				  y2 -= 1;
				} 
		   int c2 = y2 / 100;
		   int d2 = y2 % 100;
		 }



thank you guys so much for the help!!!

Is This A Good Question/Topic? 0
  • +

Replies To: day in week help!

#2 ghost97cobra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-February 08

Re: day in week help!

Posted 13 February 2008 - 12:20 PM

d = the julian day? so do i need to do int d = is_day_of_year (int year, int month, int day)?
Was This Post Helpful? 0
  • +
  • -

#3 letthecolorsrumble   User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: day in week help!

Posted 13 February 2008 - 12:46 PM

View Postghost97cobra, on 13 Feb, 2008 - 12:20 PM, said:

d = the julian day? so do i need to do int d = is_day_of_year (int year, int month, int day)?

I hope for the good health of your fingers that you are taught arrays and loops ASAP ;)
Was This Post Helpful? 0
  • +
  • -

#4 ghost97cobra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-February 08

Re: day in week help!

Posted 13 February 2008 - 12:52 PM

yeah we havnt learned that yet... he said it would make life so easy but thats in 2 weeks awsome right :) i know loops so is there a way to make a for loop function to make this work?
Was This Post Helpful? 0
  • +
  • -

#5 letthecolorsrumble   User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: day in week help!

Posted 13 February 2008 - 01:00 PM

#include <iostream>
  
using namespace std;
	
void menu ();		
void wrt_menu ();	
void test_leap_year ();
bool deal_with_it ( char event );
bool is_leap_year ( int year );
void wait_up ();
void test_days_in_month ();
int  days_in_month ( int year, int month );
int  year;
int  month;
int  days;
bool is_valid_date ( int year, int month, int days );
void test_valid_date ();
void day_of_year ();
int  is_day_of_year ( int year, int month, int days );
void day_in_week ();
	
int main (){
	  cout << "\n\n Project 2 the date project \n\n";
	  menu ();
	  cout << "\n\n End of Project 2";
	  return EXIT_SUCCESS;
}		  
  
void menu (){
	 bool done = false;
	 char event;
	 while ( ! done ){	
		 wrt_menu();
		 cin >> event;
		 done = deal_with_it ( event );
	}	
}	  
	  
void wrt_menu (){	  
		  
	 cout << " Date Program					 Kenneth Eddy\n\n";
	 cout << " L: Test for leap year.\n";
	 cout << " M: Days in a month.\n";
	 cout << " V: valid date.\n";
	 cout << " Y: day in Year.\n";	
	 cout << " W: day in Week.\n";
	 cout << " E: Expanded date.\n";
	 cout << " Q: Quit.\n\n\n";
	 cout << " Enter your choice [ L, M, V, Y, W, E, Q ] :";
	
}
	
bool deal_with_it ( char event ){	  
	switch ( event ){
	   case 'l':
	   case 'L':
		  test_leap_year ();
		  break;
	   case 'm':  
	   case 'M':
		  test_days_in_month ();
		  break;
	   case 'v':
	   case 'V':
		  test_valid_date ();	
		  break;
	   case 'y':
	   case 'Y':
		  day_of_year ();
	   case 'q':
	   case 'Q':
		 return true;
		 break;
	 }
	   return false;
}
	  
void wait_up (){  
	cout << "\n Enter any key to continue:";
	char fake;  
	cin >> fake;  
}  
		  
void test_leap_year (){  
	cout << " Test for Leap year\n";
	cout << " \n Enter a year \n";
	int year;  
	cin >> year;
	  if ( is_leap_year(year)){
		  cout <<"\n\n"<< year << " is a leap year";
	  }
	  else{
		  cout << "\n\n" << year << " is not a leap year";
	  }
	  wait_up ();
}
  
bool is_leap_year ( int year ){
	  if ( year % 400 == 0 ) return true;
	  if ( year % 100 == 0 ) return false;
	  if ( year % 4   == 0 ) return true;
							 return false;
}
  
   void test_days_in_month (){
	  cout << "\ndays in month test\n";
	  cout << "\n Enter a year";
	  int year;
	  cin >> year;
	  cout << "\n Enter a number for a month 1 = jan etc. to find the days in the month:\n";
	  int month;
	  cin >> month;
	  int days = days_in_month (year,month );
	  cout <<"\n\n year:" << year << "\nmonth:\n" << month;
	  cout << "\nhas" << days << "days";
  }
  
   int days_in_month ( int year, int month ){
	  switch ( month ){
		case 1 :			
		case 3 :
		case 5 :
		case 7 :
		case 8 :
		case 10 :
		case 12 :
		   return 31;
		   break;
		case 4 :  
		case 6 :
		case 9 :
		case 11 :  
		   return 30;
		   break;
		case 2 :
			if (is_leap_year(year)){
			   return 29;
			}
			else {
			   return 28;
			}
			break;
		 default:
			cout << "Invalid Month\n\n";
			return 0;
			break;
			
	  }
 }
		
bool is_valid_date ( int year, int month, int days ){		
   if ( month < 1 )  return false;
   if ( month > 12 ) return false;
   if ( days < 1 )  return false;
   if ( days > days_in_month ( year, month )) return false;
   return true;
		  
}	  
		
void test_valid_date (){		  
	 cout << "\n Enter a year:";
	 int year;
	 cin >> year;	
	 cout << "\n Enter a month:";
	 int month;
	 cin >> month;		  
	 cout << "\n Enter a day:";
	 int days;  
	 cin >> days;
		if ( is_valid_date ( year, month, days )){
			cout << year << month << days << " Is a Valid date ";
		}  
		else {
			cout << "\n" << year << month << days << "Is not a valid date";
		}
  
  }									  
		  
int  is_day_of_year ( int year, int month, int days ){

			int theDayOfYear=0;
			for(int i=1;i<month;i++)
				theDayOfYear += days_in_month(year,i);
			return theDayOfYear+days;
			
		  /*switch (month)
			{
				case 1 :
				  return days;
				  break;
				case 2 :
				  return 31 + days;
				  break;	
				case 3 :
				  if (is_leap_year(year))
					{
					  return 60 + days;
					} else{
					 return 59 + days;
					}
					 break;
				case 4 :
				   if (is_leap_year(year))
					{
					 return 91 + days;	
					} else{
					 return 90 + days;
					}
					 break;
				case 5 :
					if (is_leap_year(year))
					{
					 return 121 + days;
					} else{
					 return 120 + days;
					}		
					 break;
				case 6 :
					  if (is_leap_year(year))
					{
					 return 152 + days;
					} else{
					 return 151 + days;
					}
					 break;
				case 7 :
					   if (is_leap_year(year))
					{
					 return 182 + days;
					} else{
					 return 181 + days;
					}
					 break;
				case 8 :
					   if (is_leap_year(year))
					{
					 return 213 + days;
					} else{
					 return 212 + days;
					}
					 break;
				case 9 :
					if (is_leap_year(year))
					{
					 return 244 + days;
					} else{
					 return 243 + days;
					}
					 break;
				case 10 :
					   if (is_leap_year(year))
					{
					 return 274 + days;
					} else{
					 return 273 + days;
					}
					 break;
				case 11 :
					   if (is_leap_year(year))
					{
					 return 305 + days;
					} else{
					 return 304 + days;
					}
					 break;
				case 12 :
						 if (is_leap_year(year))
					{
					 return 336 + days;
					} else{
					 return 335 + days;
					}
					 break;
				default:
					cout<<"Invalid input\n\n";
					return -1;
					break;
				}*/				
}	
					
void day_of_year (){			
		  cout << "\n Enter a year";
		  int year;  
		  cin >> year;	
		  cout << "\n Ente a month:";
		  int month;
		  cin >> month;
		  cout << "\n Enter a day";
		  int days;  
		  cin >> days;
		  int day =  is_day_of_year ( year, month, days );
			  if ( is_valid_date ( year, month, days )){			  
					cout << "\nThe day in year is:" << day;
			  }
			  else{	
					cout << "\n Invalid date!";
			  }	  
				   
}		  
void day_in_week (){  
		  cout << "\n Enter the Year:";
		  int year;
		  cin >> year;
		  cout << "\n Enter the month:";
		  int month;
		  cin >> month;
		  cout << "\n Enter the day:";
		  int days;
		  cin >> days;  
		  int m2 = month-2;
		  int y2 = year;
		  

		  if ( month < 3){
			  m2 += 12;
			  y2 -= 1;
		  }
		   int c2 = y2 / 100;
		   int d2 = y2 % 100;
}



Check out the day of the year function... and experience the power of using loops.
Was This Post Helpful? 0
  • +
  • -

#6 ghost97cobra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-February 08

Re: day in week help!

Posted 13 February 2008 - 01:18 PM

o ok gotcha sweet that helps for the day of year but i still need to figure out how to set up the day in week to get sunday monday etc
Was This Post Helpful? 0
  • +
  • -

#7 letthecolorsrumble   User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: day in week help!

Posted 13 February 2008 - 01:56 PM

View Postghost97cobra, on 13 Feb, 2008 - 01:18 PM, said:

o ok gotcha sweet that helps for the day of year but i still need to figure out how to set up the day in week to get sunday monday etc



I am working on that. It may take a while. You could use the day of the year function to find the day, then find the week of the year via the previous result and then find name of the day. I am not sure of my logic but it may work.

Hint: the modulo operator (%)

This post has been edited by letthecolorsrumble: 13 February 2008 - 02:04 PM

Was This Post Helpful? 0
  • +
  • -

#8 ghost97cobra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-February 08

Re: day in week help!

Posted 13 February 2008 - 03:22 PM

k i talked to my prof and he said to
use a fuction to get the year month and day than use another fuction to get the
{
int m2= month -2;
int y2 = year ;
if ( m < 3 )
{
m2 += 12;
y2 -=1;
}
int c2 = y2 /100;
int d2 = y2 % 100;
}
i need to get the d of the year from the is_day_of_year function so should i do
int d = is_day_of_year (int year, int month, int days);
than i need to make a funtion with a switch statement right that does
switch (day_in_week)
{
case o :
cout << "\n sunday";
does that logic look right or should i do it another way? thank u alot for this help!
Was This Post Helpful? 0
  • +
  • -

#9 letthecolorsrumble   User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: day in week help!

Posted 13 February 2008 - 03:27 PM

View Postghost97cobra, on 13 Feb, 2008 - 03:22 PM, said:

k i talked to my prof and he said to
use a fuction to get the year month and day than use another fuction to get the
{
int m2= month -2;
int y2 = year;
if ( m < 3 )
{
  m2 += 12;
  y2 -=1;
}
int c2 = y2 /100;
int d2 = y2 % 100;
}
i need to get the d of the year from the is_day_of_year function so should i do
int d = is_day_of_year (int year, int month, int days);
than i need to make a funtion with a switch statement right that does
switch (day_in_week)
 { 
  case o :
	cout << "\n sunday";

does that logic look right or should i do it another way? thank u alot for this help!


How do you know that the year start with a sunday? or monday and so on?
Was This Post Helpful? 0
  • +
  • -

#10 ghost97cobra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-February 08

Re: day in week help!

Posted 13 February 2008 - 03:48 PM

this is what i got now
void ymd_day_in_week ()
		{		   
		  cout << "\n Enter the Year:";
		  int year;		
		  cin >> year;
		  cout << "\n Enter the month:";
		  int month;   
		  cin >> month;
		  cout << "\n Enter the day:"; 
		  int days; 
		  cin >> days;
		  int day_in_week =  test_day_in_week ( int year, int month, int days );
		  cout <<"\n"<< day_in_week; 
		 }			 
		  
void test_day_in_week ( int year, int month, int days )
		{
		  int d = is_day_of_year ( int year, int month, int days );
		  int m2 = month-2;
		  int y2 = year;   
			if ( month < 3)
				{
				  m2 += 12;
				  y2 -= 1; 
				} 
		  int c2 = y2 / 100;
		  int d2 = y2 % 100;
		  int day_in_week = [ d + ( 13 * m2 -1 ) / 5 + m2 + m2 / 4 +c2 /  4 + 5 * c2 ] % 7;
									
		 }



i am getting these errors
project2.cc: In function 'void ymd_day_in_week()':
project2.cc:326: error: expected primary-expression before 'int'
project2.cc:326: error: expected primary-expression before 'int'
project2.cc:326: error: expected primary-expression before 'int'
project2.cc: In function 'void test_day_in_week(int, int, int)':
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:342: error: expected primary-expression before '[' token
line 326 is
int day_in_week = test_day_in_week ( int year, int month, int days );


to my knowlege i dont i just use the formula and it will solve it for me.
" because of where leap year lands, the simplest of these forumlas start the year in march."
Was This Post Helpful? 0
  • +
  • -

#11 letthecolorsrumble   User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: day in week help!

Posted 13 February 2008 - 03:51 PM

View Postghost97cobra, on 13 Feb, 2008 - 03:48 PM, said:

this is what i got now
void ymd_day_in_week ()
		{		   
		  cout << "\n Enter the Year:";
		  int year;		
		  cin >> year;
		  cout << "\n Enter the month:";
		  int month;   
		  cin >> month;
		  cout << "\n Enter the day:"; 
		  int days; 
		  cin >> days;
		  int day_in_week =  test_day_in_week ( int year, int month, int days );
		  cout <<"\n"<< day_in_week; 
		 }			 
		  
void test_day_in_week ( int year, int month, int days )
		{
		  int d = is_day_of_year ( int year, int month, int days );
		  int m2 = month-2;
		  int y2 = year;   
			if ( month < 3)
				{
				  m2 += 12;
				  y2 -= 1; 
				} 
		  int c2 = y2 / 100;
		  int d2 = y2 % 100;
		  int day_in_week = [ d + ( 13 * m2 -1 ) / 5 + m2 + m2 / 4 +c2 /  4 + 5 * c2 ] % 7;
						
		 }



i am getting these errors
project2.cc: In function 'void ymd_day_in_week()':
project2.cc:326: error: expected primary-expression before 'int'
project2.cc:326: error: expected primary-expression before 'int'
project2.cc:326: error: expected primary-expression before 'int'
project2.cc: In function 'void test_day_in_week(int, int, int)':
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:342: error: expected primary-expression before '[' token
line 326 is
int day_in_week = test_day_in_week ( int year, int month, int days );


to my knowlege i dont i just use the formula and it will solve it for me.
" because of where leap year lands, the simplest of these forumlas start the year in march."

void ymd_day_in_week ()
		{		   
		  cout << "\n Enter the Year:";
		  int year;		
		  cin >> year;
		  cout << "\n Enter the month:";
		  int month;   
		  cin >> month;
		  cout << "\n Enter the day:"; 
		  int days; 
		  cin >> days;
		  int day_in_week =  test_day_in_week ( year, month, days );  //changed
		  cout <<"\n"<< day_in_week; 
		 }			 
		  
int test_day_in_week ( int year, int month, int days ) //changed
		{
		  int d = is_day_of_year ( year,  month,  days ); //changed
		  int m2 = month-2;
		  int y2 = year;   
			if ( month < 3)
				{
				  m2 += 12;
				  y2 -= 1; 
				} 
		  int c2 = y2 / 100;
		  int d2 = y2 % 100;
		  int day_in_week = (d + ( 13 * m2 -1 ) / 5 + m2 + m2 / 4 +c2 /  4 + 5 * c2 ) % 7; //changed
				  return day_in_week;  //added
}



This post has been edited by letthecolorsrumble: 13 February 2008 - 03:54 PM

Was This Post Helpful? 0
  • +
  • -

#12 ghost97cobra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-February 08

Re: day in week help!

Posted 13 February 2008 - 03:58 PM

k changed the int day_in_week = test_day_in_week ( int year, int month, int days );
to
int day_in_week = test_day_in_week ( year, month, days );
that took the 326 error away and added these
project2.cc: In function 'void ymd_day_in_week()':
project2.cc:326: error: void value not ignored as it ought to be
project2.cc: In function 'void test_day_in_week(int, int, int)':
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:342: error: expected primary-expression before '[' token


haha u beat me to it! we have a im convo pretty much going on

haha u beat me to it! we have a im convo pretty much going on
Was This Post Helpful? 0
  • +
  • -

#13 letthecolorsrumble   User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: day in week help!

Posted 13 February 2008 - 04:01 PM

View Postghost97cobra, on 13 Feb, 2008 - 03:58 PM, said:

k changed the int day_in_week = test_day_in_week ( int year, int month, int days );
to
int day_in_week = test_day_in_week ( year, month, days );
that took the 326 error away and added these
project2.cc: In function 'void ymd_day_in_week()':
project2.cc:326: error: void value not ignored as it ought to be
project2.cc: In function 'void test_day_in_week(int, int, int)':
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:332: error: expected primary-expression before 'int'
project2.cc:342: error: expected primary-expression before '[' token


haha u beat me to it! we have a im convo pretty much going on

haha u beat me to it! we have a im convo pretty much going on


Just because you are new to this, doesn't mean I am very good at it. Though I didn't need to take the code to my compiler to remove the errors :) Did you get the desired result?

One more thing: You didn't use d2 = y2%100; anywhere in the formula, I don't know how the formula should work , but if you have calculated d2, I guess it should be used somewhere.

This post has been edited by letthecolorsrumble: 13 February 2008 - 04:40 PM

Was This Post Helpful? 0
  • +
  • -

#14 ghost97cobra   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 11-February 08

Re: day in week help!

Posted 13 February 2008 - 06:16 PM

it says d2 is the last two digits of the year, in the system where the next ear does not start untill march. wat ever that means i know that it starts this whole thing from the month of march. i worked on it some more and i got to this point i now have one error
project2.cc: In function 'void ymd_day_in_week()':
project2.cc:328: error: void value not ignored as it ought to be
void ymd_day_in_week ()
		{	   
		  cout << "\n Enter the Year:";
		  int year;  
		  cin >> year;
		  cout << "\n Enter the month:";
		  int month;
		  cin >> month;
		  cout << "\n Enter the day:";
		  int days;
		  cin >> days;
		  int day_in_week =  test_day_in_week ( year, month, days );
		  cout <<"\n"<< day_in_week;
		 }
					   
void test_day_in_week ( int year, int month, int days )
		{
		  int d = is_day_of_year ( year, month, days );
		  int m2 = month-2;
		  int y2 = year;
			if ( month < 3)
				{
				  m2 += 12;
				  y2 -= 1;
				}
		  int c2 = y2 / 100;
		  int d2 = y2 % 100;
		  int day_in_week = (d + ( 13 * m2 -1 ) / 5 + m2 + m2 / 4 +c2 / 4 + 5 * c2 ) % 7;
					 
		 }
void the_day_in_week ( int day_in_week )
		  {
		   switch (day_in_week)
			{
			 case 0:
				cout << "\n sunday";
				break;
			 case 1:
				cout << "\n monday";
				break;
			 case 2:
				cout << "\n tuesday";
				break;
			 case 3:
				cout << "\n Wensday";
				break;
			 case 4:
				cout << "\n thursday";
				break;
			 case 5:
				cout << "\n Friday";
				break;
			 case 6:   
				cout << "\n saturday";
				break;
			  }	  
			} 


is void the one type should it be int test_day_in_week ( int year, int month, int days )???

ight well i got it to run the program but when i press w in the menu to load the function it doesnt work!
 bool deal_with_it ( char event )
   { 
	switch ( event )
	 {
	   case 'l':
	   case 'L':
		  test_leap_year ();
		  break;
	   case 'm':
	   case 'M':
		  test_days_in_month ();
		  break;
	   case 'v':
	   case 'V':
		  test_valid_date ();
		  break;
	   case 'y':
	   case 'Y':
		  day_of_year ();
		  break;
	   case 'w':
	   case 'W':
		  ymd_day_in_week ();
		  break;
	   case 'q':
	   case 'Q':
		 return true;
		 break;
	 }
	   return false; 
   }  


Was This Post Helpful? 0
  • +
  • -

#15 letthecolorsrumble   User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: day in week help!

Posted 13 February 2008 - 06:25 PM

..

This post has been edited by letthecolorsrumble: 13 February 2008 - 06:30 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2