Thread: Please Help

  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Rep Power

    Please Help

    I am a new member trying to learn c programming and I am doing my homework and got stuck with this question and I can't figure it out

    An electrical engineer wishes to calculate the equivalent resistance value for an electronic
    board. The total resistance value depends if the resistors are placed in parallel or series. For
    resistors in series, the resistance is calculated by adding the values in Ohms (r1+r2+...) of the
    individual resistors. For resistors in parallel, the resistance is calculated by the following
    formula: 1 / (1/r1 + 1/r2 + ...). Note that the maximum number of resistors in a board is 100.
    Write a program that first asks the user if the resistors are placed in series or parallel, then asks
    the user for the values of resistors in Ohms (we do not know how many resistors - use 0 as
    sentinel to end entry) and then calculates and prints out the total resistance.
    Your program must have two user defined functions: one for the series computations and
    another for the parallel computations

    please help
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Rep Power
    What have you done so far?

    Can you for example, get as far as "reading all the input up to the 0 as
    sentinel to end entry"?

    Knowing whether you can do this much allows us to give you specific advice.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    Limited! All parallel or all serial. The only reason to limit the maximum number of resistors is to follow a frequent pattern shared with novels,
    int main() {
      return 0;
    This is so simple you can combine acquisition with computation.

    process_data has the possibilities for serial or parallel resistor connection. You'll need to save that information from the acquire_input, and by some data sharing mechanism make it available for the rest of the program.

    How will you handle bad data? By testing the value returned from a scanf function? Can I enter resistors using color codes black brown red orange yellow green blue violet grey white? Will you compute error tolerances? Gold == 5%, Silver == 10%, or precision resistor. Would you allow 12000 Ohms to be input as 12k?

    What data type will you use? If integers, you might find the value of a parallel combination is infinite. Something about integer divisions of 1/(1+|n|) being 0.

    This problem is particularly fun with Iverson notation, implemented as an interactive programming language that gives a three space prompt.. Here's test data for inputs 4 8 3 0 in parallel and in series.
       s =: +     NB. serial combination of linear circuit elements
       p =: s&.%  NB. parallel combo.  The serial combination under reciprocal.
       4 s 8 s 3  NB. 4 8 and 3 Ohm resistors connected in series.
       4 p 8 p 3  NB. 4 8 and 3 Ohm resistors connected in parallel.
    Last edited by b49P23TIvg; July 20th, 2013 at 01:59 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo