forgive me qwerty, but I'm not understanding how to use or implement the clear and delay functions above. Do I combine the two program blocks as one program? When I tried to compile them, it said "clock_t" was undefined. do I define it as an int or float before it is used, or should it be included in the library??
Got it!!! thanks for passing this on, and helping me implement it. No more using the "dreaded system(cls)"!!!
So... if I understand this correctly, I can create a C++ library file with any complex piece of code that does a specific function; #include<it>, and with a simple command perform all of the "hidden" code in any future program I write??? wow!
Not exactly. To use a header file that is in your normal working directory, replace the arrow brackets with quotes (i.e. #include "it").
If the header file is in the libraries, then use the arrow brackets.
now I have a new problem, and this ties into another thread I was on;
the following code is designed to check if a keyboard key is pressed. if one is, it evaluates what to do with it, if not, it continues to display outputs. I had this program working, but when I put the delay function in, it interferes with the rest of the program?!?!? is the return millisec*1000; line confusing the program with a value it doesn't know what to do with?? and what can I do with it?
Am I the only one seeing the problem with performing a multiplication, a subtraction, and a float to integer conversion (this is just ridiculous) inside the condition of a tight loop?
I think what you meant to do was this:
1 2 3 4 5
void wait(int seconds){
clock_t endwait;
endwait=clock()+seconds*CLOCKS_PER_SEC;
while (clock()<endwait);
}
CLOCKS_PER_SEC varies from system to system. In Windows it's 1000, in Linux it's 1000000.
In any case, this a horrible way to do this if you don't like to see your CPU running a marathon while your program is taking a nap.