I've been writing this code, but I don't really know what's wrong. I'm a bit of a beginner, but I'm still able to see that this is a scoping issue. Regardless, it seems to work if there is a cout statement. Why? I've tried using j as a static integer but it didn't work. Perhaps simply because I did not understand it well enough.
int id, i(0), j;
cout << "Please type the ISBN # and ID # of the copy you wish to delete." << endl;
cin >> thecopy >> id;
string fname = "../data/" + thecopy + ".txt";
ifstream fin(fname.c_str());
while (fin.good()){
fin >> c[i];
if(c[i].ID == id){
j = i;
}
cout << j; //this statement makes it so j keeps its value
i++;
}
//cout << j ; this always gives 0
if(c[j].reader != "None"){
cout << "The copy is currently lent out, so it cannot be deleted.\n";}
else {
....}
Thanks!