Q:

C++ program to determine the color of chess square

belongs to collection: C++ programs on various topics

0

C++ program to determine the color of chess square

All Answers

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

Determine the color of a chess square board in C++

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

int main()
{
	char string[10], x;
	cout << "Enter the coordinates of the square, \
	\nthe first coordinate A to H and second coordinate 1 to 8: ";
	cin.getline(string, 10);
	x = string[0];
	x = tolower(x);
	string[0] = x;
	if (string[0] == 'a' || string[0] == 'c' || string[0] == 'e' || string[0] == 'g')
	{
		if (string[1] == '1' || string[1] == '3' || string[1] == '5' || string[1] == '7')
			cout << "Black square";
		else
			cout << "White square";
	}
	else
	{
		if (string[1] == '1' || string[1] == '3' || string[1] == '5' || string[1] == '7')
			cout << "white square";
		else
			cout << "Black square";
	}

	return 0;
}

Output

 
First run:
Enter the coordinates of the square,
the first coordinate A to H and second coordinate 1 to 8: C5
Black square

Seccond run:
Enter the coordinates of the square,
the first coordinate A to H and second coordinate 1 to 8: F3
white square

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

total answers (1)

C++ programs on various topics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ program to find the power of a number using lo... >>
<< Topological sort implementation using C++ program...