I can't figure out what am I doing wrong with this program in which just by typing row and column user gets the color of chess block.
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<unsigned int> (time(0)));
char answer;
int row;
char column;
cout << "Would you like to know a square on the chess board on the basis of row and column entered (y/n) ? " << endl;
cin >> answer;
cout << "Enter a row number and column letter of a square on a chess board" << endl;
cin >> row;
cin >> column;
while (toupper(answer) == 'Y')
{
int count = 0;
int num = 8;
if (toupper(column) == 'a', 'c', 'e', 'g')
{
if (row % 2 == 0)
{
cout << "Row, Col:" << row << " ," << column << " is a black space" << endl;
}
else
{
cout << "Row, Col:" << row << " ," << column << " is a white space" << endl;
}
}
else
{
if (row % 2 != 0)
{
cout << "Row, Col:" << row << " ," << column << " is a black space" << endl;
}
else
{
cout << "Row, Col:" << row << "," << column << " is a white space" << endl;
cout << "The number of valid coordinates entered was " << count << endl;
}
if (row < num || toupper(column) > 'h')
{
cout << row << column << " is not a valid coordinate!" << endl;
cout << " Row numbers are from 1 - 8 and column letters are from a - h." << endl;
Oh Thank you!! I don't know why i missed it but anyways when the code ends and when I run it, it just gets messed up... I have this code and i still have to add that if row exceeds 8 and column exceeds 'h' then there is an error message that it is an invalid input but the more i try the more messy it gets.
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<unsigned int> (time(0)));
char answer;
int row;
char column;
cout << "Would you like to know a square on the chess board on the basis of row and column entered (y/n) ? " << endl;
cin >> answer;
cout << "Enter a row number and column letter of a square on a chess board" << endl;
cin >> row;
cin >> column;
while (toupper(answer) == 'Y')
{
int count = 1;
int num = 8;
if ( (toupper(column) == 'a' || toupper(column) == 'c' || toupper(column) == 'e' || toupper(column) == 'g'))
{
if (row % 2 == 0)
{
cout << "Row, Col:" << row << " ," << column << " is a black space" << endl;
}
else
{
cout << "Row, Col:" << row << " ," << column << " is a white space" << endl;
}
}
else
{
if (row % 2 != 0)
{
cout << "Row, Col:" << row << " ," << column << " is a black space" << endl;
}
else
{
cout << "Row, Col:" << row << "," << column << " is a white space" << endl;
cout << "The number of valid coordinates entered was " << count << endl;
Thank you.... but when I add that if row exceeds 8 and column exceeds 'h' then there is an error message that it is an invalid input but the more i try the more messy it gets. The answer gets all messed up and doesn't show the right answer!!
Now I have got this code and it is not right and i don't know what is wrong!!!.
include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<unsigned int> (time(0)));
char answer;
int row;
char column;
cout << "Would you like to know a square on the chess board on the basis of row and column entered (y/n) ? " << endl;
cin >> answer;
cout << "Enter a row number and column letter of a square on a chess board" << endl;
cin >> row;
cin >> column;
while (toupper(answer) == 'Y')
{
int count = 1;
int num = 8;
while (row<1 || row > 8 && tolower(column)<'a' || tolower(column) > 'h');
{
cout << row << ", " << column << "is not a valid coordinate! " << endl;
cout << "Row numbers are from 1 - 8 and column letters are from a - h." << endl;
}
if ((toupper(column) == 'A' || toupper(column) == 'C' || toupper(column) == 'E' || toupper(column) == 'G'))
{
if (row % 2 == 0)
{
cout << "Row, Col:" << row << " ," << column << " is a black space" << endl;
}
else
{
cout << "Row, Col:" << row << " ," << column << " is a white space" << endl;
}
}
else
{
if (row % 2 != 0)
{
cout << "Row, Col:" << row << " ," << column << " is a black space" << endl;
}
else
{
cout << "Row, Col:" << row << "," << column << " is a white space" << endl;
}
}
cout << "The number of valid coordinates entered was " << count << endl;
cout << "Would you like to check another square ? (Y / N)" << endl;
cin >> answer;