whats the code to make certain parts of a program print out like the computer is typing it out?
Printable View
whats the code to make certain parts of a program print out like the computer is typing it out?
get the user to input a string into an array. then you just go through a loop outputting each array spot.
is that what you meant?Code:....
cin>>array[10];
int i=0;
do
{
cout<<array[i];
i++;
}while(i != 10);
....
This question was asked less than a week ago - try searching first.
Just output char by char, and you can make your program pause between the printint.
>whats the code to make certain parts of a program print out like the computer is typing it out?
Just throw the printing of each character in a loop and pause with each iteration. Once you have that you can add other niceties like changing the time of the pause to create a more realistic human typing effect. :)
-PreludeCode:#include <iostream>
#include <cstdlib>
// For Sleep, change as required for different systems
#include <windows.h>
int irand ( int n )
{
return (int)( ( (double)rand() / ( RAND_MAX + 1.0 ) ) * n );
}
int main()
{
char msg[] = "This is a message.";
for ( char *it = msg; *it != '\0'; ++it ) {
std::cout<< *it <<std::flush;
Sleep ( irand ( 500 ) + 100 );
}
}