|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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();
}
|
| Sponsored Links |
|
|
|
|||||
|
You need to put your timing code between each printf.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
|
|||||
|
if you use two loops, the outer checking the time, the inner just cycling, you can get that effect.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Things that raise your position that are not PR | dirkfirst | Search Engine Optimization | 22 | 05-09-2008 03:27 PM |
| [Tutorial] Seven Things Every User Should Know | PC101 | Tutorials | 14 | 06-13-2007 02:05 PM |
| may be off a couple days | littlefranciscan | The Lounge | 9 | 02-11-2007 04:42 PM |
| Things about women and Men | priorityone | The Lounge | 0 | 01-15-2007 09:00 PM |
| 10 Things That Will Make Or Break Your Website | xXHalfSliceXx | Website Design | 10 | 01-04-2007 06:38 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |