PDA

Click to See Complete Forum and Search --> : File Loop Help


DeepBlueCode
Jan 24th, 2002, 10:27 AM
do
{
inFile >> arrProNum[cnt] >> arrProDesc[cnt] >> arrProPrice[cnt] >> arrProTax[cnt];
total++;
}

This loop refuses to input from a file. Here is the text in the file:

00001 Bread 2.00 N
00002 Butter 2.35 T
00003 Soup 3.59 N
00004 Carrots 2.79 N
00005 Potatos 5.89 T

Anybody know why this does not loop these products into these parallel arrays?

Thanks much in advance.

kedaman
Jan 24th, 2002, 10:42 AM
do? you don't have do's in C++, only while() and for(;;) should your loop be infinite? shouldn't you have cnt++ instead of total++?

CornedBee
Jan 24th, 2002, 12:43 PM
there is do...while, which is valid C/C++ code. But there is no pure do.

DeepBlueCode
Jan 24th, 2002, 01:33 PM
That cnt is used later in the program, I need total for something else. Now, how can I fix my code, and yes, Do...while loops are valid in C++. Any reccomendations for my code, though?

CornedBee
Jan 25th, 2002, 02:57 AM
You need to increment cnt every time you loop.

DeepBlueCode
Jan 25th, 2002, 09:49 AM
do
{
inFile >> arrProNum[total] >> arrProDesc[total] >> arrProPrice[total] >> arrProTax[total];
total++;
}
while (inFile);

There's the new code, I found that before I got home and checked out the post again, but thanks, that's a big deal, lol. Does anybody know why it still doesn't input stuff right?

kedaman
Jan 25th, 2002, 10:29 AM
and i thought do was a vb thing hehe :p
no, did you check if the file was opened correctly?