Thread: need while(for(loop)) to be condition

  1. #1
    Registered User
    Join Date
    Dec 2005

    need while(for(loop)) to be condition

    hi im writing a program that need the condition of the do... while loop to be a for loop.
    well at least thats what i think i need .
    the format is i have a class and made an array of objects(h[])
    for (i=0;i<total;i++)
        while (h[i].product<AccumNum)
          }//first while brace
    }//for brace
    }//do brace
        while (for (i=0;i<total;1++){h[i].product<AccumNum;})
    the array size of h is user defined in an int named total.
    the members of the class are float num1, num2 and sum
    is it possible to use a for loop as the while loops condition
    edit... sorry i forgot to say the perpouse of these loop is to check that all product=more than the total accumnum
    so if i have 3 sums
    say product 1 is 3*4=12
    product2 is 6*4=24
    product 3 is 7*4=28
    so if accum number was made to 12 then it would all be valid
    but if accum number was say 30 then none would be valid so it would have to loop again
    making product1 3*5
    product2 6*5
    product3 7*5
    my example sum are not true to a proper value but thats the idea of the loop
    Last edited by thestien; 10-12-2006 at 06:54 AM.

  2. #2
    Registered User
    Join Date
    Dec 2005
    sorry if this is bumping but i felt it needed another post
    the do... while loop is intended to use the bottom while as the while part of that loop.
    if it doesnt could you please tell me a way in which it would thank you in advance.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    You'd have to write a function containing the for loop and returning false if any comparison fails, but this still looks bad to me. And inefficient. Don't forget inefficient.

    Oh, and if h starts out with any element smaller than AccumSum, the loop will probably go on until AccumSum overflows. (Not entirely sure about the numeric relationships between sum and AccumNum.) The whole thing is completely broken.

    What is AccumSum supposed to be? Because right now it's nonsensical.
    Also nonsensical is the name of the sum member, because sum is usually the result of an addition, but you put the result of a multiplication in it, which is usually called product.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Dec 2005
    i have every thing written on paper in pusedo codeish
    ok the funtion would be something like this maybe?
    bool somefn(i have no idea what goes in here)
    { for (i=0;i<total;i++)
    if  (h[i].product<AccumNum)
    { return false}
    im not very good at c++ yet but im trying to learn so please be patient with me if i make no sense thank you
    also if this type of function would work how would i impliment it into the do while loop i made?

    i know the code may seem inefficient but i wrote it before without classes or anything like that so now im trying to rewrite it in a different way
    Last edited by thestien; 10-12-2006 at 07:04 AM.

  5. #5
    Registered User
    Join Date
    Dec 2005
    ok i cant for the life of me make a function i dont know why but every time i do and try to put it into my it brings back some kind of error or another could sombody please tell me how to do
    a. define and write the function
    b. where t oput it into my program.

    if i put it before main it doesnt compile because the h[] hasnt been set up yet
    and if i put it after h[] has been set up i still get errors ive tried so many things that i forgot which error came from what i used do i thought the best way to get this to work would to be if you could point me in the right direction. i have read tutorials on functions but because my function will need to use and array of objects i cant quite figure out how to do it
    thank you in advance

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. condition variable on read/write locks
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 04-29-2009, 09:32 AM
  2. Condition variables
    By sethjackson in forum Windows Programming
    Replies: 16
    Last Post: 03-19-2008, 11:42 AM
  3. SDL Condition variables.
    By antex in forum Game Programming
    Replies: 3
    Last Post: 11-11-2005, 07:11 AM
  4. Looping condition
    By Chaplin27 in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2005, 02:06 PM
  5. Race condition
    By Roaring_Tiger in forum C Programming
    Replies: 5
    Last Post: 10-24-2004, 09:42 PM