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
2 odpowiedzi
+ 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.
0
Thank you Sir!!!