Question

Hmm my loop skips every other line, I'm comparing this 5 15 16 17... to this 17 37 5... and trying to find when the numbers match. And I'm not sure why it's skipping a line.

for(int j=0;j<fileMaxLines;j++){

        for(int k=0;k<fileMaxLines;k++){
            //cout <<"            " <<EInfo[j].idSE <<endl;
            if(EInfo[j].idSE == ETran[k].idIV){
                temphours = ETran[k].numbOfHoursIV;

                 cout <<EInfo[j].idSE << " -->" << ETran[k].idIV;
                 cout << "right"<<endl;
                 k=fileMaxLines;
                 break;
            }
            else{
                //cout <<EInfo[j].idSE << " -->" << ETran[k].idIV << endl;
            }
            cout <<EInfo[j].idSE << " -->" << ETran[k].idIV << endl;
        }
        EInfo[j].numbOfHoursSE = temphours;
             j++;

      }
Was it helpful?

Solution

You're increasing j twice:

for(int j=0;j<fileMaxLines;j++){ // here

    for(int k=0;k<fileMaxLines;k++){
        //cout <<"            " <<EInfo[j].idSE <<endl;
        if(EInfo[j].idSE == ETran[k].idIV){
            temphours = ETran[k].numbOfHoursIV;

             cout <<EInfo[j].idSE << " -->" << ETran[k].idIV;
             cout << "right"<<endl;
             k=fileMaxLines;
             break;
        }
        else{
            //cout <<EInfo[j].idSE << " -->" << ETran[k].idIV << endl;
        }
        cout <<EInfo[j].idSE << " -->" << ETran[k].idIV << endl;
    }
    EInfo[j].numbOfHoursSE = temphours;
         j++; // and here

  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top