Thread: how do u say like H (wait 1 second) I

  1. #1
    Registered User Prodigy's Avatar
    Join Date
    May 2002
    Posts
    25

    If ur not dumb plz help

    Hello, i would like to know how would u do like if u wanted to say hello but i your program say it like this: H (pause a second) E (pause a second) L (pause a second) L (pause a second) O
    for a dos program

    would i go
    Code:
    #include<iostream> 
    #include<ctime> 
    
    int main() 
    { 
    
    float secs = 1; 
    clock_t delay = secs * CLOCKS_PER_SEC; //convert to clock tics 
    clock_t start = clock(); 
    while(clock() - start < delay) 
    ; 
    cout << "H";
    
    
    float secs = 1; 
    clock_t delay = secs * CLOCKS_PER_SEC; //convert to clock tics 
    clock_t start = clock(); 
    while(clock() - start < delay) 
    ; 
    cout << "I";
    
    return (0); 
    }

    Thank you

    (i use dev and visual)
    Last edited by Prodigy; 05-05-2002 at 07:32 PM.
    And the cows moo...
    AIM:ProdigyCpp
    E-Mail:[email protected]
    If you like my avatar plz dont copy it go to:
    http://www.dragid.com/

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    Have you tried it?
    I'd suggest that for simplicity you define a delay function. Take a look at the code Prelude gave you in your other thread.

    void mesleep .....

    The value passed to the mesleep function is the amount of delay you require. (just glanced so I don't know if it was in seconds or milliseconds)

    like
    ....
    mesleep (1);
    cout << "H";
    mesleep(1);
    cout <<"E";

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    317
    Just like Azuth said only with your code it would be like this:

    #include<iostream.h>
    #include<ctime>

    void holdon( float sec)
    {
    clock_t delay = sec * CLOCKS_PER_SEC; //convert to clock tics
    clock_t start = clock();
    while(clock() - start < delay)
    ;
    }

    void main()
    {
    holdon(1);
    cout<<"H";
    holdon(1);
    cout<<"E";
    //ect
    }

    Hope this helps.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    To make each char appear in turn, you may need to flush the output buffer

    cout << "H";
    cout.flush();

  5. #5
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Why are you guys complicating it.. The below code will do it

    Code:
    # include <iostream.h>
    # include <dos.h>
    
    
    main()
    {
    char str[5]={"HEllO"};
    for(int i=0;i<5;i++)
    	{
    
    	cout<<str[i];
    	delay(500);
    	}
    
    return 0;
    }

    You will have to replace the delay and the header dos.h with the one compliant with your compiler since they are not standard... But this code will compile on most of the compilers (Borland , Turbo etc etc)

    Always try to simplify your entire program using loops and other structures...
    Last edited by vasanth; 05-06-2002 at 05:08 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why wait cursor still turning on?
    By Opariti in forum Windows Programming
    Replies: 0
    Last Post: 05-22-2009, 02:28 AM
  2. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  3. Signals, fork(), wait() and exec()
    By DJTurboToJo in forum C Programming
    Replies: 7
    Last Post: 03-18-2008, 09:14 AM
  4. Boom, Headoshot!!
    By mrafcho001 in forum A Brief History of Cprogramming.com
    Replies: 50
    Last Post: 07-21-2005, 08:28 PM
  5. anybody with experience using the wait() function?
    By flawildcat in forum C Programming
    Replies: 7
    Last Post: 04-22-2002, 02:43 PM