Thread: A Looped Array Or If Statements?

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    16

    A Looped Array Or If Statements?

    Hi:::

    I am relatively new to programming and am trying to assemble a project that involves some math calculations.

    I have a set of A values that I want divided by B values, each contain about 13 constants. And each set contains the same constants.

    A values (12, 18, 21 etc.)
    B values (12, 18, 21 etc)



    the code preceding this calculates an answer and looks for corresponding values from A and B that fulfils that answer (it deals with slopes).

    I could find every possible slope combination that A and B fulfills such as 12/12, 12/18, 12/21 , 18/12, 18/18 etc. and preload the program with IF statements ? I am assuming there is about 20 combination answers. Does extensive IF statments bog down the program?

    Or would it be better to run a looped array?

    Thank you for your time in responding!

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by LLINE View Post
    I could find every possible slope combination that A and B fulfills such as 12/12, 12/18, 12/21 , 18/12, 18/18 etc. and preload the program with IF statements ?
    You could, but what's the point of that? What's the point of the program then?

    I am assuming there is about 20 combination answers. Does extensive IF statments bog down the program?
    Yes and no. For you, it would hardly matter one bit. In time critical code, yes, it would probably matter.

    Or would it be better to run a looped array?
    A loop + array would be much better, I think.
    Less code to type, less code to maintain, less error prone.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by LLINE View Post
    I am relatively new to programming

    Does extensive IF statments bog down the program?
    Don't worry about optimizing your code, just write the cleanest solution you can. Premature optimization is generally considered a no-no, but later you'll learn some "preemptive optimizations" that may be more sensible to apply, especially if you are developing real-time software, games, etc.

    But for now, strive for clean, robust code.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    16

    Thanks for the replies!!

    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  2. Creating a menu that reads input via an array?
    By Nalif in forum C Programming
    Replies: 6
    Last Post: 09-29-2006, 09:21 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM