C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 23rd, 2005, 11:03 PM
CSstudent!== CSstudent!== is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 2 CSstudent!== User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 51 sec
Reputation Power: 0
Programing a Day Counter, need help!!

Alright I'm programing a simple day counter here where the user enters 2 years

ex) 2001 and 2004

now the program is suposed to figure out how many days are between those 2 years

*note* have to use a for-loop only.

heres what I have set up..

for (year=year; year<=yearTwo; year++)

I honestly have no idea what formula to use or what to, any help is appreciated, thanks!

Reply With Quote
  #2  
Old January 24th, 2005, 05:55 AM
marmo marmo is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 37 marmo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 20 sec
Reputation Power: 4
Code:
    long CalcNumDays( int nStartYear, int nEndYear )
    {
  	 if( nStartYear >= nEndYear )
 	 return 0;
  
    	 long lNumDays(0);
    	 int nYearDifference = nEndYear - nStartYear;
    
    	 for( int i(0); i < nYearDifference; ++i )
    		   lNumDays += 365;
    
    	 return lNumDays;
    }
    

Reply With Quote
  #3  
Old February 1st, 2005, 04:13 PM
groggory groggory is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 groggory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 17 sec
Reputation Power: 0
Don't forget leap years :-)

Years evenly divisible by 4 are leap years, with the exception of centurial years that are not evenly divisible by 400

Alright, my coding is VERY rusty. But I'm taking more C++ this semester so I better brush up fast.

Please critique my code for this...I know there is an elegant way. I HATE big nested if else loops. There is a way to do this nicely.

Code:
long CalcNumDays( int nStartYear, int nEndYear ){
 long days(0);
 int year(365),leapYear(366);
 
 for(int i(nStartYear);i<nEndYear; i++){   
  if(i%4==0){
   if(i%100==0){
	if(i%400==0)
	 days+=year;
	else
	 days+=leapYear;
   {
   else
	days+=leapYear;
  }
  else
   days+=year;
 }
   
 return days;  
}

Reply With Quote
  #4  
Old February 1st, 2005, 06:23 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
sorry to post this...but: how the hell do you write code with spaces here?. I've tried to do so, and I get all lines of code align to the left (without the classic TAB). Whenever I use the -> button, the code gets all messy.....I'm just trying to know this, in order to be able to help people here more efitiently.

Thanks....

Anibal.

PS: look at this!!

void bla(){
asdfasdf;

}

Reply With Quote
  #5  
Old February 1st, 2005, 07:32 PM
groggory groggory is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 2 groggory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 38 m 17 sec
Reputation Power: 0
I write in textpad, then copy and past it in. I think tabs are translated to spaces.



Quote:
Originally Posted by Anibal
sorry to post this...but: how the hell do you write code with spaces here?. I've tried to do so, and I get all lines of code align to the left (without the classic TAB). Whenever I use the -> button, the code gets all messy.....I'm just trying to know this, in order to be able to help people here more efitiently.

Thanks....

Anibal.

PS: look at this!!

void bla(){
asdfasdf;

}

Reply With Quote
  #6  
Old February 2nd, 2005, 02:11 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
Thanks....I'll give it a try!...lets see

function bla(){
return 0
}

Damn...it didn't work!!!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Programing a Day Counter, need help!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway