Day number program with a small twist

I need help with a program that gets the daynumber(day of the year for

Page 1 of 1

4 Replies - 4621 Views - Last Post: 12 February 2009 - 01:11 AM Rate Topic: -----

#1 crackisgood4u  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 11-February 09

Day number program with a small twist

Posted 11 February 2009 - 06:08 AM

I need help with a program that gets the daynumber(day of the year for example dec 31 2009 would be 365) for 2 different dates then uses a recursive function to get the number of days in between those 2 dates. I am having trouble with my fist function (which sucks).


The function is get day number. whenever I try to get the day number it only gives me the day of the month, for example january 5th day number is 5, but february 5th's daynumber is also showing up as 5, december 21st shows up as 21. please help me this assignment is already late. I have broken down and started to cry 2 times trying to figure it out...

/* Joshua Thibodeaux ######NAME####.cpp
   Program due: ##-##-09
   Program Description: This is a description of the program. 
	Design:
	 
	 1.prmpt user for input of first date
	 prmpt user for input of second date
	 
   2.Use getDayNumber2 to obtain 3 intagers  month, day and year for the second date.
   
   3.Use function compareDates to determine which date is earliest
	  If year1 is less than year2
		return false
	  else
		if year
	 
	 
	 
	   20. Programer ID 
	  
		c06pp11 < dates.txt  <- input file
		
*/

#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;

//Function Declarations
int getDayNumber(int day, int month, int year); //Function Decleration
int isLeapYear (int year); //Function Decleration

int main (int day1, int month1, int year1, int day2, int month2, int year2, char dash, int dayNumber1)//Function Decleration 

{ 
	
	cout << "Enter dates then press enter. " << endl;
	system ("pause");
	cin >> month1>> day1 >> year1;
	cout << month1 << "-" << day1 << "-" << year1 << endl;
	
	cin >> month2 >> day2 >> year2;
	cout << month2 << "-" << day2 << "-" << year2 << endl;
	
	dayNumber1 = getDayNumber (month1, day1, year1);
	
	cout << "The getDayNumber function has retuned: " << dayNumber1 << endl;
	system ("pause");
	
	
  //  int isLeapYear (year1);
	
  //  int isLeapYear (year2);
	
	
	

}	
	
	
	
	
	
	
int getDayNumber(int month, int day, int year) //Function Definition

{
	cout << month << "-" << day << "-" << year << endl;
	
	if (month == 1);
  {   
	 return day;
  } 
	 
	 if (month == 2);
  {	
	 return (day + 31);
  }	 
		 if (month == 3);
  {	
	 return (day + 59);
  }	 
		 if (month == 4);
  {	
	 return  (day + 90);
  }	 
		 if (month == 5);
  {	
	 return  (day + 120);
  }	 
		 if (month == 6);
  {	
	 return (day + 181);
  }	  
		 if (month == 7);
  {	
	 return  (day + 212);
  }		 
		 if (month == 8 )
  {	
	 return  (day + 243);
  }	 
			 if (month == 9)
  {	
	 return  (day + 273);
  }	 
			 if (month == 10)
  {	
	 return  (day + 273);
  }	 
				if (month == 11)
  {	
	 return  (day + 304);
  }	 
			 if (month == 12)
  {	
	 return  (day + 334);
  }	 
  
   
}	
	
  
	
	
	
	
	
	 
I have to get this function working properly before I can move onto a bool leap year function

Is This A Good Question/Topic? 0
  • +

Replies To: Day number program with a small twist

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Day number program with a small twist

Posted 11 February 2009 - 06:10 AM

you posted in the C# forum.
Was This Post Helpful? 0
  • +
  • -

#3 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Day number program with a small twist

Posted 11 February 2009 - 02:19 PM

Your main() function is not defined correctly. The arguments it is using are not standard. Change
int main (int day1, int month1, int year1, int day2, int month2, int year2, char dash, int dayNumber1)//Function Decleration


to
//Function Decleration
int main () {
	int day1;
	int month1;
	int year1;
	int day2;
	int month2;
	int year2;
	char dash; 
	int dayNumber1;
...




See Main function

Also, remove the semi-colons from your if statements in getDayNumber() - if (month == 1); etc.

This post has been edited by n8wxs: 11 February 2009 - 03:00 PM

Was This Post Helpful? 0
  • +
  • -

#4 crackisgood4u  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 11-February 09

Re: Day number program with a small twist

Posted 12 February 2009 - 12:44 AM

View Postn8wxs, on 11 Feb, 2009 - 01:19 PM, said:

Your main() function is not defined correctly. The arguments it is using are not standard. Change
int main (int day1, int month1, int year1, int day2, int month2, int year2, char dash, int dayNumber1)//Function Decleration


to
//Function Decleration
int main () {
	int day1;
	int month1;
	int year1;
	int day2;
	int month2;
	int year2;
	char dash; 
	int dayNumber1;
...




See Main function

Also, remove the semi-colons from your if statements in getDayNumber() - if (month == 1); etc.




Ok now im having trouble with a function that returns true if the first date comes after the second, this is what i got and it doesn't work, I cant figure it out

/* Joshua Thibodeaux c06pp11.cpp
   Program due: ##-##-09
   Program Description: This is a description of the program. 
	Design:
	 
	 1.prmpt user for input of first date
	 prmpt user for input of second date
	 
   2.Use getDayNumber2 to obtain 3 intagers  month, day and year for the second date.
   
   3.Use function compareDates to determine which date is earliest
	  If year1 is less than year2
		return false
	  else
		if year
	 
	 
	 
	   20. Programer ID 
	  
		c06pp11 < dates.txt  <- input file
		
*/

#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;

//Function Declarations
int getDayNumber(int day, int month, int year); //Function Decleration
int isLeapYear (int year); //Function Decleration
int compareDates(int day1, int month1, int year1, int day2, int month2, int year2); //Function Decleration 

int main () {
	int day1;
	int month1;
	int year1;
	int day2;
	int month2;
	int year2;
	char dash;
	int dayNumber1;
	int dayNumber2;
	int dateOrder;
	
	cout << "Enter dates then press enter. " << endl;
	system ("pause");
	cin >> month1>> day1 >> year1;
	cout << month1 << "-" << day1 << "-" << year1 << endl;
	
	cin >> month2 >> day2 >> year2;
	cout << month2 << "-" << day2 << "-" << year2 << endl;
	
	dateOrder = int compareDates (int day1, int month1, int year1, int day2, int month2, int year2); 
	
	if (dateOrder = 1) //if date order
	{
	 cout << "Reverse Dates..." << endl;
	}				  //end if date order
	else
		
	cout << "Reverse Dates..." << endl;
	
	dayNumber1 = getDayNumber (month1, day1, year1);
	dayNumber2 = getDayNumber (month2, day2, year2);
	
	if (month1 > 2)
	{
	dayNumber1 = dayNumber1 + isLeapYear (year1);
	}
	if (month2 > 2)
	{	
	dayNumber2 = dayNumber2 + isLeapYear (year2);
	}	
	
	cout << "The getDayNumber function has retuned: " << dayNumber1 << " for dayNumber1" << endl;
	cout << "The getDayNumber function has retuned: " << dayNumber2 << " for dayNumber2" << endl;
	
	
	system ("pause");
	
	
	
	
	
	

}	
	
	
	
	
	
	
int getDayNumber(int month, int day, int year) //Function Definition

{
	cout << month << "-" << day << "-" << year << endl;
	
	if (month == 1) //0
  {   
	 return day;
  } 
	 
	 if (month == 2)
  {	
	 return (day + 31); //31
  }	 
		 if (month == 3)
  {	
	 return (day + 31 + 28);//59
  }	 
		 if (month == 4)
  {	
	 return  (day + 31 + 28 + 31);//90
  }	 
		 if (month == 5)
  {	
	 return  (day + 31 + 28 + 31 + 30);//120
  }	 
		 if (month == 6)
  {	
	 return (day + 31 + 28 + 31 + 30 + 31);//151
  }	  
		 if (month == 7)
  {	
	 return  (day + 31 + 28 + 31 + 30 + 31 + 30);//181 
  }		 
		 if (month == 8 )
  {	
	 return  (day + 31 + 28 + 31 + 30 + 31 + 30 + 31);//212
 }	
			 if (month == 9)
  {	
	 return  (day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31);//243
  }	 
			 if (month == 10)
  {	
	 return  (day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 );//273
  }	 
				if (month == 11)
  {	
	 return  (day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 );//304
  }	 
			 if (month == 12)
  {	
	 return  (day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30);//334
  }	 
  
   
}   // End of getDayNumber

	 int isLeapYear(int year) // Function Deffinition
{
   int isLeap = 0;
   if((year % 4) == 0)
	 {
	 isLeap = 1;
	 if((year % 100) == 0)
	   {
	   isLeap = 0;
	   if((year % 400) == 0)
		 {
		 isLeap = 1;
		 }
	   } 
	 }
   return isLeap;
}  //end of isLeapYear
	
 int compareDates(int day1, int month1, int year1, int day2, int month2, int year2) //Function Defenition
 {
 if (year1 > year2) //If year is greater
   {

	return 1;
   }				// end if year is greater
 if (year1 == year2)   // if year is equal
   {	
	if (month1 > month2) // if month is greater
	  {

	return 1;
   }					// end of if month is greater
	if (month1 == month2) // if monthis equal
	  { 
	   if (day1 > day2) // day is greater
	  {

	return 1;
   }					 //end if day is greater
   
   else		  //else?
   
	 return 0;		   //end else?
   }	// end if month is equal
   } //end of compareDates   
	

Was This Post Helpful? 0
  • +
  • -

#5 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: Day number program with a small twist

Posted 12 February 2009 - 01:11 AM

You might like to look here for several examples of 'date programs' to give you some more ideas ...

http://developers-he.../index.p...opic,106.0.html

Shalom,
David
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1