Color the text [C++ Based]

Color the text is a simple computer programming project, that displays text on the screen in various colors based on the option chosen by the users.

This is a simple programming project based on C++ code, The program first asks for the user input and displays the text in the corresponding color on the screen. The magic in the program is done by the C++ function setcolor() which is described or coded explicitly in the program itself.

The program, first of all, defines the function setcolor() and describes its statements.  Then the program asks for user input which ranges from 1 to 14, then a text is displayed on the screen with the corresponding color of the number entered by the user.

Check out other interesting C++ projects posted on bestengineeringprojects.com 

  1. Telephone Diary using C++
  2. Employee Management System Using C++
  3. 3D Ball, graphics-based project on C++
  4. Base Conversion based on C++

The project is useful in understanding the basics of graphics in computers using c++ and playing with colors.

so here is the code:

#include “global.h” //header files, function prototypes, & classes

void setcolor(unsigned short color) { //begining of set color funtion
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); //gets std handle
SetConsoleTextAttribute(hCon,color); //Sets Console Text Attribute HCon color.
} //end of set color funtion
int main() { //begining of main funtion
printf(“What color do you want the text to be?(1 = blue, 2 = green, 4 = red, 14 = yellow)”); //displays text
scanf(“%d”, &C.I); //scans number
setcolor(C.I); //sets color
cout << ” _____ ____ ____ _____\n”; //displays text
cout << “|_ _|| __ || ___||_ _|\n”; //displays text
cout << ” | | | __||__ | |\n”; //displays text
cout << ” | | | |__ __| | | |\n”; //displays text
cout << ” |_| |____||____| |_|\n”; //displays text
return 0; //returns 0
} //end of main function

One Thought to “Color the text [C++ Based]”

  1. Vighnesh Chaulkar

    Very nice

Leave a Comment