I am having 2 main issues with this function:
1) For some reason my while loop is working but not correctly. If the user enters 0 rather than the while loop terminating and proceeding to the next line of code in the main function, the program begins to repeat infinite request for input information.
2) When the user needs to enter the tool name, if there is a space in the tool name the program also goes crazy and begins to output infinitely. I think that it is the function getline that can deal with also capturing a space in between strings. For example it works fine for “Hammer” but goes crazy with “Lawn mower”. How can I correct this?
My code is the following:
// user enters information, which is copied into file
while (partNumber > 0 && partNumber <= 100)
{
// user enters tool name, quantity and unit price
cout << "Enter the tool name: ";
cin >> setw( 20 ) >> toolName;
cout << "Enter the quantity in stock and the unit price for the tool\n? ";
cin >> inStock;
cin >> unitPrice;
// set the record for the part number, tool name, quantity in stock, and unit price
tool.setPartNumber( partNumber );
tool.setToolName( toolName );
tool.setInStock( inStock );
tool.setUnitPrice( unitPrice );
// seek position in file of user-specified record
outTools.seekp( ( tool.getPartNumber() - 1 ) * sizeof ( Tools ) );
// write user-specified information in file
outTools.write( reinterpret_cast < const char * >( &tool ),sizeof ( Tools) );
//enable user to enter another account
cout << "Enter tool identification number (1 to 100, 0 to end input)\n? ";
cin >> partNumber;
} // end while loop
} // end enterRecords function