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

Join Date
Jul 2013
Posts
1
Rep Power
0

Hi
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

2. 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.
3. 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,
Code:
```int main() {
acquire_input();
process_data();
produce_report();
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.
Code:
```   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.
15
4 p 8 p 3  NB. 4 8 and 3 Ohm resistors connected in parallel.
1.41176```
Last edited by b49P23TIvg; July 20th, 2013 at 02:59 PM.