| Xyexs (22) | |||
|
Hey, i'd like to know how to make timers (if possible). This is my current code(not done, im still learning)
What it is going to do is: 1: ask for a number 2: ask for seconds, minutes or hours 3: count up up to the amount of seconds,minutes or hours and update every second Here is the error message... 'sleep': identifier not foundso assuming "sleep" doesn't exist, How do i make timers? i was learning c++ and trying to make some programs ... to learn ... and realised i did not know ANY kinds of timers and started this project. so assuming "sleep" doesn't exist, How do i make timers? | |||
|
Last edited on
|
|||
| Pickle Gunner (63) | |||
You would call on the function like: wait(1000,0)Where 1000 would be the time (Not in seconds though) and 0 would be there to be the starting time. It's a recursive function. (Essentially a function that loops by calling on its self) | |||
|
|
|||
| Xyexs (22) | |
| Thank you, i will try when i can | |
|
|
|
| Xyexs (22) | ||||
Probably worked, lol .. but there is other problems too...
will post code in another message, to much for 1 post | ||||
|
|
||||
| Xyexs (22) | |||
^ ^ : : the code(ps: not done AND ima beginner) | |||
|
Last edited on
|
|||
| Kelliepy (1) | |
| You have lots of problem... but i have no anyone Idea... :( | |
|
|
|
| coder777 (2378) | |
|
What are you trying to do? on line 63: if (secminhour=="seconds")do the same for line 67/71 (the quotes) I don't know if Pickle Gunner was trolling, but wait function is nonsense. What you're looking for is Sleep() (note the capital S)http://msdn.microsoft.com/en-us/library/windows/desktop/ms686298%28v=vs.85%29.aspx | |
|
|
|
| Xyexs (22) | ||||||
|
Thanks sir, but it did not work i am afraid... linking new code and the 3 error messages left(still learning, dont be mad if i am missing something basic) Errors:
Code:
| ||||||
|
|
||||||
| coder777 (2378) | |
for Sleep() you need to #include <windows.h> (look at the link).line 86: cout<<hours<<":"<<minutes<<":"<<seconds;
| |
|
|
|
| Xyexs (22) | |||
|
You, sir, are a gentleman! NEW FRIGGIN ERRORS?!?!?!?!?
did i fail at defining minutes, seconds and hours? EDIT: Solved :D i just didnt give ethem any numbers | |||
|
Last edited on
|
|||
| coder777 (2378) | |
| you need to initialize minutes/seconds/hours to 0 on line 11/12/13 | |
|
|
|
| Xyexs (22) | |||
|
NOT SOLVED!!! new problem: the program keeps on counting after limit, ex Console:how many? Me:1 Console:minutes, seconds or hours me:minutes console: counting up to 1 minutes.(yes! it sounds weird, and it is weird!) 0:0:1 0:0:2 0:0:3 0:0:4 0:0:5 0:0:6 0:0:7 0:0:8 0:0:9 0:0:10 ... until ... 0:1:0 0:1:1 0:1:2 and it just goes on... why? Code:
| |||
|
Last edited on
|
|||
| Darkmaster (341) | |
|
change the or in your while to and || --> && line 73 | |
|
Last edited on
|
|
| Xyexs (22) | |||
|
actually solved that one by myself... but now ... a small problem My conversation with the xonsole:
it should stop at 0:0:1 and close the program | |||
|
Last edited on
|
|||
| Darkmaster (341) | |
|
does it start at 0 or at 1? because the output tells me it counts from 1 to 2 , which is excactly 1 second | |
|
|
|
| coder777 (2378) | |
calculate the amount of seconds from the entered amountreplace the while loop on line 73 with a for loop that simply runs to the amount of seconds. Btw: line 15: this while (run=true) assigns true to run (the loop will never end). you want while (run==true) or simply while (run)
| |
|
|
|
| Xyexs (22) | |||
|
starts at 0:0:1 BUT i tried int seconds=-1it was like 0:0:0 0:0:1 0:0:2 How many? EDIT: solved!
Thanks, coder77 and darkmaster for helping me :D | |||
|
Last edited on
|
|||
| coder777 (2378) | ||
Consider the for loop | ||
|
|
||
| Darkmaster (341) | |
|
coder777 is right just handle 1minute as 60seconds and 1hours as 3600seconds. this way you only need to check for for seconds. also use a for loop where you simply run from 0 to the stoptime and inside the for loop you do nothing besides waiting a second and printing the output | |
|
Last edited on
|
|
| Xyexs (22) | |
|
lol this is the 1293642183764891723689172349871234978123465712530412341234601236491237641982346128734561287936897126478512436512783452716345t12098381253487652346127936412653421736479821341287359th time i ask for your help on this post... Console:how many? me:1 Console:seconds, minutes or hours? me:minutes console:counting up to 1 minutes 0:0:0 The timer has counted up to 1 minutes What the fuck? | |
|
|
|