Thread: simple question...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    simple question...

    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!

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    >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.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    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!

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    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.

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Ok thanks. But I am getting one more probeblem that is relaly making me.

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

  6. #6
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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.

  7. #7
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    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++?

  8. #8
    if your running windows
    look up these


    Sleep();


    GetTickCount();



    nuff said.

  9. #9
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    so is std:: the new c++ stnaderd? Becuase I have ben using cout for a long time.

    And thanks once again!

  10. #10
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    usually you put:
    Code:
    using namespace std;
    at the top of your code so that your code isn't riddled with std::'s, just looks plain ugly.

  11. #11
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    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.

  12. #12
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Sleep

    notice the capitalization. I believe it works by including windows.h

  13. #13
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ok thanks. It works now.

  14. #14
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Quote Originally Posted by jverkoey
    usually you put:
    Code:
    using namespace std;
    at the top of your code so that your code isn't riddled with std::'s, just looks plain ugly.
    I just have a habit of doing std::

    But I suppose either way is fine, I think there is a faq article about it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM