Jump to content

Stopwatch!


Anonymouse
 Share

Recommended Posts

Believe it or not, I HAVE ACTUALLY MUSTERED THE PATIENCE TO PROGRAM A NEW C++ PROGRAM!

It's basically a stopwatch. Start it and it counts up, hours, minutes, seconds, and milliseconds :)

#include <iostream>

#include <ctime>


using namespace std;


int main() {

	int total = 0;

	int h = 0, m = 0, s = 0, ms = 0;

	while ( true ) {

		total++;

		ms++;

		if (ms > 999) {

			ms = 0;

			s++;

			if (s > 59) {

				s = 0;

				m++;

				if (m > 59) {

					m = 0;

					h++;

				}

			}

		}

		cout << "\rtime: " << h << ":" << m << ":" << s << "." << ms;

		cout.flush();

		usleep(1000);

	}

	cout << "\n";

	return 0;

}

It should compile, if you get an error about usleep not existing, then your standard C library fails :P

Link to comment
Share on other sites

xD Mouse, the purpose of a stopwatch is to accurately record time... you fail at programming if it can't do that right.

Link to comment
Share on other sites

  • 2 months later...

I'd like to see you guys do better! You'd probably FAIL at it to. Making a stopwatch in C++ is very difficult, believe it or not.

Link to comment
Share on other sites

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.