Results 1 to 8 of 8

Thread: C++ Countdown Timer Question

  1. #1
    Join Date
    Aug 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default C++ Countdown Timer Question

    Ok, i know how to create a very simple countdown timer:

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <windows.h>
    #include <conio.h>
    
    using namespace std;
    
    void clrscr()
         {
         system("cls");
         }
    
    main()
    {
        unsigned int timer;
        
        cout << "Timer Set To: ";
        cin >> timer;
        
        for (timer>0;timer--;) 
        {
            Sleep(1000);
        }
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    But my question to you guys is if there is a way to perform other things in my program while waiting for the timer to finish. If possible, could you please explain? thanks in advance.

    btw, i joined the site in 2006 and am back... so yay... lol.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Why have you included <conio.h> and then used DOS-specific commands to clear the terminal? From Googling, it appears that the relevant function for that is _clrscr(). Additionally, your indentation is inconsistent, and you have omitted the argument and return types for main(), which is considered bad style.

    Judging from your level of code here, you're not nearly ready for this yet, but here's an introduction to the hell of low-level threaded programming in Windows: http://www.mycplus.com/tutorial.asp?TID=288.

    I must say, if you're just starting out with C/C++ programming, you've picked one of the worst operating systems on which to begin. I suggest moving to a POSIX-compliant OS such as Linux or BSD: the interface is much simpler. The Win32 API is a beast, and not something I'd want to tackle at all, to be honest, much less at the same time as trying to learn basic C++.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Actually i have been doing c++ for about a month taking it seriously.. isnt my first programming language, and i have used linux based OS... i know i left out the the argument and return types for main() that is because i get some funny error when i include <conios.h> and i included that because in the earlier one i was messing with getch() and other pre-defined functions, forgot to take it out.. and the indentation is bad because i didnt take alot of time on messing with this.. infact it took 5 minutes not even.. just wanted to show you an example and see if you could answer the question given above: can i perform other things in my program while waiting for the timer to finish? which i kinda feel like you strayed from....

    also im talking about console application not windows application, im definately not ready to mess with WindowsAPI... lol complicated just to make a window pop up for me... so im guessing theres no way?? btw i googled it but got nothing, so maybe it is impossible.

    Thanks for the pointers though.. and if you wanna count me as a c++ beginner you most certainly can because im only at using pointers in my book: Sam Teach Yourself C++ In 21 Days... LOL

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    can i perform other things in my program while waiting for the timer to finish? which i kinda feel like you strayed from....
    I did not, although perhaps I did not make my answer quite clear enough: you can indeed, most likely using threads (thus, the tutorial), although you may also be able to set something up using polling.
    i know i left out the the argument and return types for main() that is because i get some funny error when i include <conios.h>
    I'm not sure of the relation here... perhaps fixing that error would be a more appropriate response.
    and i included that because in the earlier one i was messing with getch() and other pre-defined functions, forgot to take it out..
    I did not mean to imply that you should remove it from your program; rather, in fact, that you should make more extensive use of it (in this case, to avoid calling external applications).
    also im talking about console application not windows application, im definately not ready to mess with WindowsAPI...
    The difference is between 'Windows application' and 'application for other OS', not between 'Windows console application' and 'Windows GUI application'. Anything complex in Windows requires fiddling with the Windows API, including non-graphical endeavours such as network or threaded programming.
    i have used linux based OS...
    That's nice. My suggestion was that you should be learning to program with it, rather than starting on Windows. Once you are familiar with the language itself and the paradigm involved, then you can switch to Windows and perhaps begin tackling the Windows API and the horrors contained within.
    Thanks for the pointers though.. and if you wanna count me as a c++ beginner you most certainly can because im only at using pointers in my book: Sam Teach Yourself C++ In 21 Days... LOL
    *laughs* After a month? Shame on you!
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    *laughs* After a month? Shame on you!
    yeah well, i've been skipping a few days and forgetting to read and learn, so yeah. Alright thanks for the help, i'll look into it all.

    ps: i can see your posts now, wierd.

  6. #6
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by Snorkle? View Post
    Actually i have been doing c++ for about a month taking it seriously.. isnt my first programming language, and i have used linux based OS... i know i left out the the argument and return types for main() that is because i get some funny error when i include <conios.h> and i included that because in the earlier one i was messing with getch() and other pre-defined functions, forgot to take it out.. and the indentation is bad because i didnt take alot of time on messing with this.. infact it took 5 minutes not even.. just wanted to show you an example and see if you could answer the question given above: can i perform other things in my program while waiting for the timer to finish? which i kinda feel like you strayed from....

    also im talking about console application not windows application, im definately not ready to mess with WindowsAPI... lol complicated just to make a window pop up for me... so im guessing theres no way?? btw i googled it but got nothing, so maybe it is impossible.

    Thanks for the pointers though.. and if you wanna count me as a c++ beginner you most certainly can because im only at using pointers in my book: Sam Teach Yourself C++ In 21 Days... LOL
    Heh, I use Sams Teach Yourself C++ In 24 hours. I'm not even on Hour 16! You must be better with C++ than I am... Plus, to the guy who used system("cls"), that should be used minorly. It slows the computer down if you use it more than once in a single session.

    -magicyte

  7. #7
    Join Date
    Nov 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default hi

    may i know how to make a countdown timer program with design in turbo c. help me plsss.. thxs plss send in my yahoomail. jaime_ortega066@yahoo.com.ph

    thxs

  8. #8
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    design in turbo c.
    What do you mean by 'design'? Graphics?

    -magicyte

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •