0

this is the code I wrote to display the word "Hello" which will keep scrolling like a billboard. I found a problem here where the scrolling is too fast, how can I slow it down by using looping method? Thanks for your guides!

#include <iostream>
#include <cstdlib>
using namespace std;

void charH()
{
cout << "H   H"<<endl;
cout << "H   H"<<endl;
cout << "HHHHH"<<endl;
cout << "H   H"<<endl;
cout << "H   H"<<endl;
}   

void charE()
{
cout << "EEEEE"<<endl;
cout << "E    "<<endl;
cout << "EEEE "<<endl;
cout << "E    "<<endl;
cout << "EEEEE"<<endl;
}

void charL()
{
cout <<"L     "<<endl;
cout <<"L     "<<endl;
cout <<"L     "<<endl;  
cout <<"L     "<<endl;  
cout <<"LLLLL "<<endl;  
}

void charO()
{
cout <<" OOO "<<endl;
cout <<"O   O"<<endl;
cout <<"O   O"<<endl;
cout <<"O   O"<<endl;
cout <<" OOO "<<endl;
}   

void charEx()
{
cout <<"  !  "<<endl;
cout <<"  !  "<<endl;
cout <<"  !  "<<endl;
cout <<endl;
cout <<"  !  "<<endl;
}

 void displayAll()
{
charH();
cout<<endl;
charE();
cout<<endl;
charL();
cout<<endl;
charL();
cout<<endl;
charO();
cout<<endl;
charEx();
 }  

void Accept(char variable)
{
switch (variable)
{
    case 'H' : charH();
               break; 
    case 'E' : charE();
               break;   
    case 'L' : charL();
               break; 
    case 'O' :charO();
               break; 
    case '!' : charEx();
               break; 
    default : cout << " " << endl; system("pause"); break;
}
}

void AcceptAChar(char choice)
{
Accept(choice); 

}

void Accept6Char(char a, char b, char c, char d, char e, char f)
{
AcceptAChar(a);
cout << endl;
AcceptAChar(b);
cout << endl;
AcceptAChar(c);
cout << endl;
AcceptAChar(d);
cout << endl;
AcceptAChar(e);
cout << endl;
AcceptAChar(f);
}   

void rotate(char& a, char& b, char& c, char& d, char& e, char& f)
{
char temp = a;
a=b;
b=c;
c=d;
d=e;
e=f;
f=temp;
Accept6Char( a,  b,  c,  d,  e, f);

}   

int main()
{

char a = 'H';
char b = 'E';
char c = 'L';
char d = 'L';
char e = 'O';
char f = '!';

for(int i=0; i >=0; i=i++)
{
    system("cls");
    rotate(a, b, c, d, e, f);
}   

}
David G
  • 94,763
  • 41
  • 167
  • 253
user2611244
  • 51
  • 2
  • 4
  • 9

2 Answers2

1

Have a look at one of the APIs to suspend the thread or process temporarily, like sleep() or delay().

On Linux, there is sleep() and usleep(). On MSDOS with Borland, there is delay(), with Windows, there is sleep().

wallyk
  • 56,922
  • 16
  • 83
  • 148
0

You can use this function between each letter or line:

#include <unistd.h>
usleep( microseconds );

Source: Sleep for milliseconds

See: http://linux.die.net/man/3/usleep

Community
  • 1
  • 1
Homer6
  • 15,034
  • 11
  • 61
  • 81