Question: Why is my code not opening the text file ? ? I keep getting an error message ? ? Am I inserting the text file
Why is my code not opening the text file I keep getting an error message Am I inserting the text file into the program incorrectly
#include
#include
using namespace std;
Function to calculate piece value
int getPieceValuechar piece
switch piece
case P: case p: return ;
case N: case n: return ;
case B: case b: return ;
case R: case r: return ;
case Q: case q: return ;
default: return ; For kings and empty spaces
Function to check if piece is black
bool isBlackPiecechar piece
return piece A && piece Z;
Function to read and display chessboard, and calculate scores
void processChessboardifstream& file
char board;
int blackScore whiteScore ;
Reading chessboard x characters
for int i ; i ; i
for int j ; j ; j
file boardij;
char piece boardij;
if piece
int value getPieceValuepiece;
if isBlackPiecepiece
blackScore value;
else
whiteScore value;
Display the chessboard
cout "Chessboard:" endl;
for int i ; i ; i
for int j ; j ; j
cout boardij;
cout endl;
Display the scores
cout "Black Pieces Value: blackScore endl;
cout "White Pieces Value: whiteScore endl;
cout endl;
int main
ifstream filechessboardstxt;
if file
cerr "Error opening file!" endl;
return ;
Processing each chessboard in the file
while file.eof
processChessboardfile;
file.close;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
