I'm having trouble writing a function that searches through an array of structures for a string value.
The structure looks like this:
struct Computer{
string Model;
string Brand;
int Price;
};
For some reason I have no problem finding the Price values, but the function that is supposed to compare a string to another string it always defaults to "not found" which is supposed to happen if the Model does not exist in the database. I checked to see if the array does have all the data, and it does.
Here is what I have
void FindModel( ifstream& Process, ofstream& Log, Computer Database[], Computer Temp, int NumItems )
{
int Position;
// Get rest of line
getline( Process, Temp.Model, '\n' );
Log << left
<< setw(30) << "Looking for Computer named:"
<< setw(38) << Temp.Model
<< endl;
Position = ModelSearch( Database, Temp, NumItems );
if ( Position = -1 )
{
Log << Temp.Model << " not found" << endl;
Log << "--------------------------------------------------------------------" << endl;
}
else
{
Log << right
<< setw(3) << Position << ": "
<< left
<< setw(26) << Database[Position].Model
<< setw(20) << Database[Position].Brand
<< setw(10) << Database[Position].Price
<< endl;
}
}
The ModelSearch function:
int ModelSearch( const Computer Database[], Computer& Temp, int NumItems )
{
int Position = 0;
while ( ( Position < NumItems ) && ( Database[Position].Model != Temp.Model ) )
Position++;
if ( Position < NumItems )
return Position;
else
return MISSING;
}