-
Flush !!
While reading data from a file to be loaded into an array, if an error occurs ont he input....an error message should be displayed and the rest of the line should be flushed....and continue on with the next line.....the code I wrote is....
Code:
fsinventoryFile>> invArray[index].itemCode;
while(!fsinventoryFile.eof() )
{
fsinventoryFile >> invArray[index].quantity
>> invArray[index].price;
while((!invArray[index].price ) || (!invArray[index].quantity))
{
cin.clear();
while(cin.get(aCh) && aCh !='\n');
cout <<"Invalid input on: "
<<invArray[index].itemCode<<endl;
}
cout<<"Record " <<index << " item code is:\t "
<<invArray [index].itemCode <<endl;
cout<<"Record " <<index << " quantity is:\t "
<<invArray[index].quantity<<endl;
cout<<"Record " <<index << " price is:\t "
<<invArray[index].price<<endl;
index++;
fsinventoryFile>> invArray[index].itemCode;
}//end of while loop
any help on this would be great....thx
Code tags added by kermi3
-
I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you ;)
For example:
Without code tags:
for(int i=0;i<5;i++)
{
cout << "No code tags are bad";
}
With Code Tags:
Code:
for(int i=0;i<5;i++)
{
cout << "This code is easy to read";
}
This is of course a basic example...more complicated code is even easier to read with code tags than without.
I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found at the link in my signature. I also suggest you take a look at the board guildlines if you have not done so already. Any further questions or ways I can help please feel free to PM me.
This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.
Good Luck,
Kermi3
-