Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Countdown problem

countdown

  • Please log in to reply
2 replies to this topic

#1 putty88

putty88

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 15 February 2009 - 11:25 AM

Hi there,

I am completely new to programming and need to learn it fast. I have been set the task of creating a day countdown in C. I need the programme to workout the difference between two dates and display the number of days inbetween that period.

Could anyone point me in the right direction to help me code this. I have read basic tutorials, but am not sure where to go next.

Thanks.
  • 0

#2 PythonPower

PythonPower

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 179 posts

Posted 15 February 2009 - 12:48 PM

Well, in C you haven't got much to play with. What functions and structures you do have are given here:

ctime (time.h) - C++ Reference

They aren't helpful at all...

I guess I would start by building a function daysInMonth(int month, int year) that took into account leap years...
  • 0

#3 c0delicious

c0delicious

    CC Newcomer

  • Just Joined
  • PipPip
  • 16 posts

Posted 16 February 2009 - 06:54 AM

Well, what you are trying to do it shouldn't be complicated, I'm going to try to walk you through an algorithm but you'll do the programming!

Ok, so you know your working with dates.. and dates have months, days, and years.. so you should start by defining those variables, or even better make them members of a class

ie:
class Date{
public :
int day;
int month;
int year;

once you have defined the class and the 'members/attributes/variables' you should write some 'methods/functions' to set a value to them, and get the value from them or just create a 'constructor' to set them values;

ie:
Date(int d, int m, int y){
day = d;
month = m;
year = y;
}
// and also a 'destructor'
~Date() { }
}; here you close the class


once you get that working then you can go ahead and write your function to get the difference between the dates.

int howManyDays(Date* a, Date* b){
// here you do the math
// and your programming
}

after that all you need is to create a 'main/driver' function to: create Two instances of the class, call the function

ie:
int main(){
Date *a = new Date(01,01,1980);
Date *b = new Date(01,01,1981);

howManyDays(a, b);

return 0;
}

Remember this is just a start to your application, and I haven't use C++ in a long time, so maybe some of this stuff will give you errors, so use your imagination, read some tutorial on the stuff that i mentioned between ' ' this.. and if you have a problem or w/e. just post
  • 0





Also tagged with one or more of these keywords: countdown

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download