Thread: I don't know how to add a timer ? Can someone help please

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    26

    I don't know how to add a timer ? Can someone help please

    Hello
    I want to add a timer to my mini quiz game and show how much time it took for the user to finish it .I want to learn how to do that in C language
    NOTE: My program only has a splash screen Allegro

    The files are attached
    A bitmap http://i58.tinypic.com/2qan4nk.jpg (I couldnt attach because of the size is above 200 kb. Please save as a BMP file )
    A text file
    A CPP file

    It is kind of urgent but any help is appreciated
    Thank you
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Oct 2013
    Posts
    26
    .......

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I want to know why you are spamming me?

    One more time and I will request you be banned!!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Registered User
    Join Date
    Oct 2013
    Posts
    26
    I am sorry staha01 i didnt mean to spam you ! I sent one message and it didnt show any messages saying sent successfully or something,so i went to my sent messages folder and there was nothing there, that is why i sent you another one because i thought the first one was unsuccessful ! Sorry for confusion !

  5. #5
    Codus Conjectus spongefreddie's Avatar
    Join Date
    Sep 2010
    Location
    USA
    Posts
    86
    Quote Originally Posted by Varun Kumar View Post
    Hello

    The files are attached
    A bitmap http://i58.tinypic.com/2qan4nk.jpg (I couldnt attach because of the size is above 200 kb. Please save as a BMP file )
    A text file
    A CPP file
    You are requesting help with C++ code in the C forum. While there is a solution in C, is this what you meant to do?
    V8 Interceptor: KDE 5.25.5 on Manjaro Linux 22.0.0 "Sikaris"
    Steering wheel: gcc 12.2.0 in Kate
    Supercharger: NASM 2.15.05
    Engine: AMD Ryzen 7 1700
    Dashboard: NVIDIA GeForce GTX 1060 6GB
    Rusty old trailer for hauling 3% of my Steam catalog: Windows 7 Pro 64bit SP1
    3 Antique Ford Model T automobiles for vintage LAN gaming: Windows XP SP3
    Sturdy buckboard for DOS LAN gaming: DOSBox 0.74-3 on Windows XP SP3

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    It might be a .cpp file, but the code is all C.

    @OP
    Strip out all the allegro code, and 9 out of 10 questions and make a simple program that just asks ONE question and times the answer.

    When you have that working, then you can copy/paste it 10 times in your code.

    Though to be honest, you really need to be using your Q.txt file (you also need an answers file as well), to really make the code much simpler.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Oct 2013
    Posts
    26
    Hi salem
    thank you for replying ! Currently i cannot take anything out and sort it because of the time limit ! Is there anyway i can still add the timer with the code i currently have ?
    thank you

  8. #8
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    It sounds like what you need to do is ask for the time once in the beginning, and once in the end, and then call difftime() with the two time_t variables you have.

    time(2): time in seconds - Linux man page
    difftime(3): calculate time diff - Linux man page

  9. #9
    Registered User
    Join Date
    Oct 2013
    Posts
    26
    @Whiteflags how do i ask the time ?
    I have absolutely zero knowledge on the header time.h

  10. #10
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I have absolutely zero knowledge on the header time.h
    That is not my problem. I gave you a reference that explains everything I think you need to know about the functions that you need to use--how to call them, and what they return. Plus, the C file that you linked to in the thread has code with time() and difftime() in it. It is hard for me to believe that at this stage you cannot do this much yourself. Without doing it completely for you, there is literally no other way I can help. Frankly, if you cheated or got lazy, you deserve to fail. You should try a little harder.
    Last edited by whiteflags; 06-03-2014 at 10:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. timer in C
    By nightking in forum C Programming
    Replies: 3
    Last Post: 01-31-2009, 05:17 PM
  2. Help with timer
    By NeMewSys in forum C++ Programming
    Replies: 4
    Last Post: 05-21-2008, 09:47 AM
  3. Timer again.
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 05-04-2005, 10:19 PM
  4. 1st timer, need help
    By coy in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2003, 11:04 PM
  5. need help with a timer
    By revelation437 in forum C++ Programming
    Replies: 10
    Last Post: 03-27-2003, 11:25 AM