Help with user input with timer

I need help on this program because i cannot seem to take the user input (seconds entered) and have my program count TICK TOCK based on what the user input. Any help would be appreciated.


#include <stdio.h>
#include <conio.h>
#include <time.h>

int main( )

{
clock_t start, end;
float total_time;


int i;
int j;
int k;
int timer;

printf("Enter any time in seconds\n ");
scanf ("%i,%j,%k", &timer);
getchar ();

printf( "Start timing\n" );
start = clock();


for ( i=0; i<10000; i++ )
for ( j=0; j<1000; j++ )
for ( k=0; k<100; k++ );
printf("TICK\n");
for ( i=0; i<10000; i++ )
for ( j=0; j<1000; j++ )
for ( k=0; k<100; k++ );
printf("TOCK\n");
for ( i=0; i<10000; i++ )
for ( j=0; j<1000; j++ )
for ( k=0; k<100; k++ );
printf("TICK\n");
for ( i=0; i<10000; i++ )
for ( j=0; j<1000; j++ )
for ( k=0; k<100; k++ );
printf("TOCK\n");
for ( i=0; i<10000; i++ )
for ( j=0; j<1000; j++ )
for ( k=0; k<100; k++ );
printf("TICK\n");
for ( i=0; i<10000; i++ )
for ( j=0; j<1000; j++ )
for ( k=0; k<100; k++ );
printf("TOCK\n");
end = clock();

total_time = ( end - start ) / CLK_TCK;

printf( "\nTotal Time Elapsed : %0.3f seconds\n", total_time );

getch();

This program works but im lost on what to do next.
[1898 byte] By [Newbie joe dirt] at [2007-11-20 10:39:01]
# 1 Re: Help with user input with timer
scanf ("%i,%j,%k", &timer); <- Here you say you want scanf to read one integer then skip a , then read a... well, you're lucky since neither %j nor %k are valid input types.What you want is to only have %i in the format string.

Your for loops produces the TICK TOCK sequence you expect but that is regardless of user input since you don't use the variable timer. The sequence is also very dependent on the speed of the PC it executes on and if compiled for debug or release (optimized).

Remove the current for loops and replace them with code that uses clock() values instead. For instance, your program should execute until clock() - start > CLK_TCK*timer. For the TICK / TOCK output, add a variable that say when it's time to print TICK/TOCK, increment it each time something is printed. To decide if print TICK or TOCK you could for instance check if 'time to print' is even or odd value.
S_M_A at 2007-11-10 3:45:55 >