Monday 7 November 2011

A countdown timer written in C

/***************************************************************************
 *   Copyright (C) 2009 by David Ronald Smith,,,   *
 *   david@debian   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#define DELAY 1000000000
int hcount;
int mcount;
int scount;
void delay(void);

int main(void)
{
printf("input the hours ");
scanf("%d", &hcount);
printf("input the minutes ");
scanf("%d", &mcount);
printf("input the seconds ");
scanf("%d", &scount);

for(;;)
{
scount--;

if(scount==-1) {
scount =59;
mcount--;
}

if(mcount== -1){
mcount=59;
hcount--;
}

if(hcount==0 && mcount==0 && scount==0){
break;
}
delay();
printf("\n%i\n", scount);
printf("\n%i\n", mcount);
printf("\n%i\n", hcount);
}
return 0;
}

void delay(void)
{
long int t;
for(t=1; t<DELAY; ++t);
}

No comments:

Post a Comment