Hey people i am having trouble with a for loop with an if statement nested in. I have read the data below
Code:
Forsyth, Frederick ;The fist of god ;A;102391
Follett, Ken ;The pillars of the earth ;A;103795
Francis, Clare ;Wolf winter ;A;112424
Smith, Wilbur ;A falcon flies ;A;151395
Forsyth, Frederick ;The day of the jackal ;A;159151
Blackmore, R.D. ;Lorna Doone ;A;193292
Smith, Wilbur ;Men of men ;A;292351
Smith, Wilbur ;The angels weep ;A;482315
James, P.D. ;Cover her face ;D;144371
James, P.D. ;Devices and desires ;D;193395
Kellerman, Faye ;Stone kiss ;D;434517
James, P.D. ;The skull beneath the skin ;D;439518
Kelly, Jim ;The water clock ;D;543951
Hoag, Tami ;Dark horse ;D;664333
Cookson, Catherine ;The silent lady ;R;151611
Cookson, Catherine ;Kate hannigans girl ;R;165163
Thompson, E.V. ;The lost years ;R;165213
Steel, Danielle ;The cottage ;R;177516
Binchley, Maeve ;Quentins ;R;261561
Alcott, Louisa ;Little women ;R;395104
Cookson, Catherine ;Rosie of the river ;R;512843
Asimov, Isaac ;Foundation ;S;165108
Barker, Clive ;Imajica ;S;172816
Barker, Clive ;The great and secret show ;S;174427
Barker, Clive ;Weaveworld ;S;282118
Clarke, Arthur C ;2001 A space odessy ;S;294561
Asimov, Isaac ;Foundation and empire ;S;313178
Asimov, Isaac ;Second foundation ;S;549201
I read this data into an array as so.
Code:
ifstream accfile ("bookdata.txt");
book b[max];
int counter = 0;
do
{
getline(accfile, b[counter].secondname, ',');
getline(accfile, b[counter].firstname, ';');
getline(accfile, b[counter].title, ';');
accfile >> b[counter].cat;
accfile.ignore(1,';');
accfile >> b[counter].bnumber;
if (accfile)
{
counter++;
}
} while (accfile && counter < max);
accfile.close(); // close file
Then i used this code here to let the user enter the author surname and display some data about the book
Code:
string authorname;
cin >> authorname;
for (int as = 0; as == counter; as++)
{
if(b[as].secondname==authorname)
{
cout << b[as].secondname << b[as].firstname << b[as].title
<< b[as].cat;
}
}
for some reason it only works if a enter Forsyth (b[0]) but noting else. Any ideas???.