A simple program to demonstrate how to use text color and sleep in Dev C++. I hope you will find my work useful.

Machine Problem in C++

Create a program that will print your  name “Jake” with a delay of 1 second. 

Color should be in alternate. (blue,red,green and yellow) using Dev C++.

blue – 1

red – 4

green – 2

yellow – 6

Program Listing

/* demo.cpp
   Jake Rodriguez Pomperada, MAED-IT, MIT
   www.jakerpomperada.blogspot.com and www.jakerpomperada.com
   jakerpomperada@gmail.com
   Bacolod City, Negros Occidental Philippines.
*/

#include <iostream>
#include <windows.h>
#include <conio.h>

using namespace std;

int main()
{
        HANDLE color=GetStdHandle(STD_OUTPUT_HANDLE); //just once
       
        // Text Color and Sleep in Dev C++
        while(!kbhit())
	{
        cout << "  ";
         SetConsoleTextAttribute(color, 1);
		cout<<"J";
        Sleep(1000);
        SetConsoleTextAttribute(color, 4);
        cout<<"a";
         Sleep(1000);
        SetConsoleTextAttribute(color,2);
        cout<<"k";
        Sleep(1000);
        SetConsoleTextAttribute(color, 6);
        cout<<"e";
}
       return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *