Hi all. I've taken a long break from my C++ studies but I'm now being shoved into finding an internship for school so I figured I'd play around and brush up on my coding. I've written this simple tabata countdown timer and I would like opinions on how it could be streamlined or written more efficiently. Also, I realize the way I wrote it makes it completely non-portable, but it suits my needs just fine for my personal use on my Debian box. Suggestions regarding how to make it portable are welcome as well, as I don't really have a whole lot of experience doing so. It's a pretty simple and straight forward little program, but I'm sure there's at least a few things I could do differently, just to gain perspective. Thanks.

Please show your code. There are a lot of ways to implement timers in Linux, some of which are thread-safe, and others are not. I do a lot of this in the work I do as a systems engineer.

Please show your code. There are a lot of ways to implement timers in Linux, some of which are thread-safe, and others are not. I do a lot of this in the work I do as a systems engineer.

LOL I'm sorry. That's my ADD in full effect. I totally forgot to post it. Here you go.

#include <iostream>
#include <typeinfo>
#include <string>
#include <stdlib.h>

using namespace std;

int main() {

    int timer0, timer1, numIntervals, currInterval;
    int startTime = 20;
    int breakTime = 10;

    cout << "How many intervals do you want: ";
    cin >> numIntervals;

    cout << "Timer will start in 5 seconds\n";
    sleep(1);

    for ( int i = 5; i > 0; i-- ) {
        cout << i << '\n';
        sleep(1);
    }

    for ( currInterval = 0; currInterval < numIntervals; currInterval++ ) {
        cout << "Interval " << currInterval + 1 << ':';
        while ( startTime > 0 ) {
                cout << '\n' << startTime;
            sleep(1);
            if ( startTime == 20 ) {
                system( "aplay ./dialog-information.wav > /dev/null 2>&1" );
            }
            startTime--;
        }
        startTime = 20;
        cout << '\n';

        cout << "Break Interval " << currInterval + 1 << ':';
        while ( breakTime > 0 ) {
                cout << '\n' << breakTime;
            sleep(1);
            if ( breakTime == 10 ) {
                system ( "aplay ./warning.wav > /dev/null 2>&1" );
            }
            breakTime--;
        }
        breakTime = 10;
        cout << '\n';
    }
    system ( "aplay ./SchoolBell.wav > /dev/null 2>&1" );
    cout << "Good Job!" << endl;

    return 0;

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.