-
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)
-
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";
-
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. :)
-
To make each char appear in turn, you may need to flush the output buffer
cout << "H";
cout.flush();
-
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...