hello,

i need to write a program that computes an equivalent resistor value if it is in either series or parallel . (in c++).
how will i write this in c++ :

[TEX] R_\mathrm{eq} = R_1 \| R_2 = {R_1 R_2 \over R_1 + R_2} [/TEX] (parallel)

[TEX] R_\mathrm{eq} = R_1 + R_2 + \cdots + R_n[/TEX](series)

thank you

Edited 6 Years Ago by cogitoergosum18: n/a

Here is something to get you started :

#include <iostream>
using namespace std;

int main(){

}

Now I am not sure about the specification. Do you ask the user to input a range of Resistor values and compute its parallel or series value, or is it just 2 values?

Edited 6 Years Ago by firstPerson: n/a

All you have to do is enter them just like you see them. Just be mindful of your parentheses.

For the series situation, you'll probably want to use a loop of some sort and just total up the user's input values.

EDIT:
You're kidding me, this thread sat for an hour and I get ninja'd. :(

Edited 6 Years Ago by Fbody: n/a

I have to ask for a range of resistor values. i have to first ask the user whether they want to compute a resistor in series or parallel, then from there i have to either compute it in series or parallel. I also have to compute the resistor value from the color code of the resistor but that is totally something different. It is basically two programs in one. but how do i actually put in the equation? just as i see them? i am using a do while loop by the way.

Edited 6 Years Ago by cogitoergosum18: n/a

Post your code. From what I got, you should be doing something like this :

float calculateParallelValues(float resistors[], const int numOfResistors){
 //...
}
float calculateSeriesValues(float resistors[], const int numOfResistors){
}
int main(){
 const int MAX_RESISTORS = 100; //maximum number of resistors
 float resistors[MAX_RESISTORS ] = {};

 get resistor values and store them into resistors array
 ask if user want series value  
    if so call calculateSeriesValues();
 else calculateParallelValues();

  return 0;
}
This article has been dead for over six months. Start a new discussion instead.