How can I make my program pause for a vertain amout of time? And how can I get the time from one end to anouther? I mean like when the user hits a key it starts then stops when it is suposed to.
Thank you again!
How can I make my program pause for a vertain amout of time? And how can I get the time from one end to anouther? I mean like when the user hits a key it starts then stops when it is suposed to.
Thank you again!
>How can I make my program pause for a vertain amout of time?
look in to the Sleep function (I think it might be windows-specific, but you should be able to find stuff on it either here or on google)
>And how can I get the time from one end to anouther? I mean like when the user hits a key it starts then stops when it is suposed to.
I'll leave that to you to figure out, I'll give you a hint:
Find a function that waits for the user to hit a key.
ok I got for the second one! I just hope the user doesn't use it at either noon or midnight.
Get the time when he/she started then time when he/she ended then subtract them. yay!
That works, but if you want it to be accurate and not have to worry too much about noon/midnight issues with the time lapsing over, look in to timer functions like GetTickCount or timeGetTime, there's other better ones out there, but those are some good ones to at least look in to and know about.
Ok thanks. But I am getting one more probeblem that is relaly making me.
In this code the if stament is not working. If you type "type" (without the ") it doesnt' work. It just pauses and notin happens, as in the correct! never pop ups! What do I have to do?Code:#include <windows.h> #include <iostream.h> #include <time.h> int main() { char user_input[100]; cout<<"type \n\n\n"; cin.getline(user_input, 5, '\n'); if(user_input=="type") { cout<<"correct!"; cin.get(); } cin.get(); }
You don't want to use == with pointers (not in this case, anyway). Look up the strcmp function in <cstring>, and that'll do the comparison for you.
or use C++ style strings
Code:#include <iostream> #include <string> int main () { std::string user_input; std::cout << "Enter text: "; std::cin >> user_input; if ( user_input == "type" ) { std::cout << std::endl; std::cout << "Correct!"; } std::cin.ignore (); std::cin.get (); return 0; }
Last edited by Vicious; 09-22-2004 at 05:35 PM.
What is C++?
if your running windows
look up these
Sleep();
GetTickCount();
nuff said.
so is std:: the new c++ stnaderd? Becuase I have ben using cout for a long time.
And thanks once again!
usually you put:
at the top of your code so that your code isn't riddled with std::'s, just looks plain ugly.Code:using namespace std;
oh that works. But I looked up the sleep() function. Here is what I found...
It suspends the process of execution for a set time. It uses the unistd.h header. I, from what I found, think it is a Unix function...
It doesn't work. It doesn't compile it doesn't reconise it.
Sleep
notice the capitalization. I believe it works by including windows.h
ok thanks. It works now.
I just have a habit of doing std::Originally Posted by jverkoey
But I suppose either way is fine, I think there is a faq article about it.