0

I have to code an algorithm.We enter 2 digits for coordinates of a point, the result must be where the point is-black or white?

pls

11th Nov 2016, 5:29 PM
Martin Veselinov
Martin Veselinov - avatar
2 Réponses
+ 1
#include <iostream> using namespace std; int main() { int x, y; char graph[5][6] = { "bwbwb", "wbwbw", "bwbwb", "wbwbw", "bwbwb" }; cout << "Enter X and Y coordinate: "; cin >> x >> y; if (x < 0 || x > 4 || y < 0 || y > 4) cout << "X and/or Y coordinates out of bounds!\n"; else { switch(graph[y][x]) { case 'b': cout << "Black"; break; case 'w': cout << "White"; break; default: cout << "Unknown"; } } return 0; } Obviously we can't create colors with the command prompt, you'd want to get graphical libraries for that, but this will do for a console application. Index of the graph goes from 0-4 on both the X and Y axis.
11th Nov 2016, 7:04 PM
Cohen Creber
Cohen Creber - avatar
0
Thank you Sir!!!
11th Nov 2016, 7:40 PM
Martin Veselinov
Martin Veselinov - avatar