For Loop Problems

This is a discussion on For Loop Problems within the C++ Programming forums, part of the General Programming Boards category; I am creating a program that calculates the beam sized needed for a certain load based on three given equation. ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    8

    For Loop Problems

    I am creating a program that calculates the beam sized needed for a certain load based on three given equation. I need to automate the selection of beam width. Which means I have to run the functions until they pass the test. I am incrementing the width by 2.(2x2 4x4....) I want my For loop to run until the if test is true and the variable test=1 and print out the statement. Right Now it seems like I can't even enter the for loop, I am only prompted for the length and load then nothing happens. I can't seem to figure out why, any suggestions would be great. I attached the source file.
    Attached Files Attached Files

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,407

    .

    Code:
    for(width=2;test=1;width+=2)
    {    loadb=buck(length,width);
         loadc=comp(width);
         result=slender(length,width);
        if(loadb<=load && loadc<=load && result==1)
        {cout<<"For a load of "<<load<<" and a length of "<<length<<" inches,recommended sqaure beam has a side of "<<width<<" inches\n";
        test=1;}
        else
        test=0;
    }
    it should be ==
    but i dont like it anyhow, why dont you use a while loop instead?

    while(test)

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    8
    I didn't like it much either, used a while loop instead, much easier. Thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  3. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 08:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21