Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-09-2007, 08:05 PM
joebenjamin joebenjamin is offline
Newbie
 
Join Date: Sep 2007
Posts: 3
Rep Power: 0
joebenjamin is on a distinguished road
Question Need Help With A Couple Things

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(); 
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-10-2007, 12:17 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

You need to put your timing code between each printf.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-10-2007, 12:32 PM
joebenjamin joebenjamin is offline
Newbie
 
Join Date: Sep 2007
Posts: 3
Rep Power: 0
joebenjamin is on a distinguished road
Smile How do I implement user input in timer?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-11-2007, 11:57 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

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


All times are GMT -5. The time now is 04:25 AM.

Contest Stats

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

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads