I have a couple programs I am working on that I cannot figure out. I am new to programming and am in the process of trying to learn more about c programming. Here is what I am trying to do with my program.
I am trying to read in a time period from the keyboard (for example 1.2 seconds, 3.4 seconds, or 8.37 seconds). Once the time has been read in, print out the word “TICK” and then wait the designated time period and print the word “TICK” again. Repeat this until there are 6 “TICK”s on the screen.
The ouptut would look something like this:
Enter a time ==> 2.27
TICK <wait 2.27 seconds>
TICK <wait 2.27 seconds>
TICK <wait 2.27 seconds>
TICK <wait 2.27 seconds>
TICK <wait 2.27 seconds>
I know my code is definetly not correct, but I do have the timer working correctly just lost on how to go about editing it to make this work.
Any Ideas or help would be great:
My code:
Code:#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", &timer); getchar (); printf( "Start timing\n" ); start = clock(); for ( i=0; i<5000; i++ ) for ( j=0; j<1000; j++ ) for ( k=0; k<100; k++ ); end = clock(); total_time = ( end - start ) / CLK_TCK; printf("TICK\n"); printf("TICK\n"); printf("TICK\n"); printf("TICK\n"); printf("TICK\n"); printf("TICK\n"); printf( "\nTotal Time Elapsed : %0.3f seconds\n", total_time ); getch(); }
You need to put your timing code between each printf.
I have this program working now, however I cannot get this to correctly work with use input. How would I set this up to ask the user a time in seconds ect.
Thanks
Joe
if you use two loops, the outer checking the time, the inner just cycling, you can get that effect.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks