Results 1 to 7 of 7

Thread: File Loop Help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Texas
    Posts
    140

    File Loop Help

    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.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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++?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    there is do...while, which is valid C/C++ code. But there is no pure do.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Texas
    Posts
    140

    So...

    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?

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You need to increment cnt every time you loop.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Texas
    Posts
    140

    Stupid accidents...

    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?

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    and i thought do was a vb thing hehe
    no, did you check if the file was opened correctly?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width