Posted by eosp on 07:51:00 10-06-2003
Write a bcd clock in c or c++ for dos/windows. Graphics optional. Programmer of nicest looking clock wins braggin' rights. Post a screenshot in your post.
Good luck
[addsig]
Posted by split on 08:09:00 10-13-2003
Here's mine. It's not pretty - neither the code nor the clock itself. The reason for the former's ugliness is C's godawful strings. I will be switching exclusively to Python and Haskell after this.
Code:
/* Binary clock */
#define WIN32_LEAN_AND_MEAN
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <windows.h>
#define OKAY 0
int militaryToNormal (int hr)
{
return ((hr > 12) ? (hr - 12) : hr);
}
int main (void)
{
struct tm curTime;
time_t t;
char binHours[9] = {0}; char binMins[9] = {0};
while (1)
{
time(&t);
curTime = *(localtime(&t));
int n1 = militaryToNormal(curTime.tm_hour);
int n2 = curTime.tm_min;
int i = 0;
for (; i < 8; i++)
{
binHours[i] = ( (n1 & 0x80) > 0 ) ? '1' : '0';
binMins[i] = ( (n2 & 0x80) > 0) ? '1' : '0';
n1 <<= 1; n2 <<= 1;
}
printf("%s:%s",binHours,binMins);
Sleep(200);
system ("CLS");
}
return OKAY;
}
Posted by split on 08:11:00 10-13-2003
Oh, and here's a screenshot:
Posted by split on 08:17:00 10-13-2003
May I make a suggestion, eosp? Make this contest open to all languages. There's no reason to restrict anything to C/C++.
[ This Message was edited by: split on 2003-10-13 08:20 ]