A PHP Error was encountered

Severity: Warning

Message: fopen(/var/cpanel/php/sessions/ea-php56/PHPSESSID3ifn96sbbfntioqlvk0p05v101t4s0qs): failed to open stream: No space left on device

Filename: drivers/Session_files_driver.php

Line Number: 174

C++ program to print your name randomly on the screen with colored text
Q:

C++ program to print your name randomly on the screen with colored text

0

C++ program to print your name randomly on the screen with colored text

This program will print the name until we do not press any key through keyboard, there are text colors and text background color is used to print the name.

Name will be print on random positions.

Following functions are used in this program:

1) kbhit() - This function returns true if key is pressed, in the program we are using while(!kbhit()), that mean program will run until any is not pressed. This function is declared in conio.h.

2) randomize() and rand() – Functions are used to generate random numbers, here we are generating random text colors and background colors till color value 16, value of X and Y co-ordinates. Functions are declared in stdlib.h.

3) textcolor(color) – This function is used to define text color, its value will be 0 to 15 (in hexadecimal: 0x00 to 0x0F). Function is declared in conio.h.

4) textbackground(color) – This function is used to define text background color, its value will be 0 to 15 (in hexadecimal: 0x00 to 0x0F). Function is declared in conio.h.

5) gotoxy(x,y) – To define X and Y co-ordinates where text will be printed.

6) cprintf(string..) - This function is similar to printf, but it is used to print the colored text on console output screen. Function is declared in conio.h.

7) delay(milliseconds) – This function is used to hold the program’s execution for given milliseconds, it is using to run loop after given milliseconds in the program. Function is declared in dos.h.

Note: program is compiled and executed on TurboC3 compiler.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <stdlib.h>

int main()
{

	int color;
	int bcolor;
	int x,y;
	int d;

	//init random to return random value each time
	randomize();
	//clears the screen
	clrscr();

	//infinite loop until key is not pressed 
	while(!kbhit())
	{
		//gerenate randon text and background color
		color =rand()%16;
		bcolor=rand()%16;
		
		//define text color 
		textcolor(color);
		//define background color
		textbackground(bcolor);
		//check if both colors are same, continue the loop
		if(color==bcolor)
			continue;
		
		//generate random X and Y Co-ordinates
		x = rand()%75;
		y = rand()%20;
		//define position to print the text 
		gotoxy(x,y);
		//print the text 
		cprintf("nerdutella");
		//delay 
		delay(100);
	}

	return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Most popular and Searched C++ solved programs with Explanation and Output

Similar questions


need a help?


find thousands of online teachers now
C++ program to demonstrate example of delay() func... >>
<< Sieve of Eratosthenes to find prime numbers using ...

A PHP Error was encountered

Severity: Warning

Message: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/cpanel/php/sessions/ea-php56)

Filename: Unknown

Line Number: 0