Closed Thread
Results 1 to 4 of 4

Thread: Need Help With A Couple Things

  1. #1
    joebenjamin is offline Newbie
    Join Date
    Sep 2007
    Posts
    3
    Rep Power
    0

    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(); 
    }

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,486
    Blog Entries
    75
    Rep Power
    143
    You need to put your timing code between each printf.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    joebenjamin is offline Newbie
    Join Date
    Sep 2007
    Posts
    3
    Rep Power
    0

    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

  5. #4
    Join Date
    Jul 2006
    Posts
    16,486
    Blog Entries
    75
    Rep Power
    143
    if you use two loops, the outer checking the time, the inner just cycling, you can get that effect.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. A Couple Questions.
    By CommittedC0der in forum General Programming
    Replies: 2
    Last Post: 10-04-2010, 02:27 PM
  2. A couple of problems
    By Mers in forum JavaScript and CSS
    Replies: 17
    Last Post: 06-24-2009, 02:12 PM
  3. Couple of Issues
    By TalAlpha in forum ionFiles
    Replies: 2
    Last Post: 03-31-2009, 07:57 AM
  4. A couple of questions
    By CrazedDoc in forum Pascal and Delphi
    Replies: 2
    Last Post: 09-17-2008, 10:49 AM
  5. Couple errors please help :-D
    By JJJIrish05 in forum C and C++
    Replies: 10
    Last Post: 03-06-2008, 04:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts