I am writing a code for a game, and I want the game to store a win/loss record in a text file... but it isn't working the way I want it to. It pulls the same random integer instead of reading from the text file, then writes that integer to the text file, but then does not read it from the text file when the instance is run again. Can I get some help?
iv=readFile(int); p=iv // (iv is for input value)
d=readFile(int); d=iv
play game
writeFile(p,d);
return 0;
}
int function readFile(int){
open, read, close
return what you read
}
void function writefile(int,int){
open,write,close
}
In this way you only have the file opened for reading, or opened for writing. Not both at the same time. You can track your error down to a function and not "Somewhere" in the haystack...
lines 9-10: I presume you want to READ fin here. If so, you have the wrong operator. It should be fin >>.
lines 9,10,17,18: You're not checking to see if the fin >> operation was successful.
If the operation failed, wins and losses (which are uninitialized variables) won;t be changed.