Help with making a function
Dear friends,
I am trying to make a function to calculate total resistance in of parallel reistors, this function should keep asking for entering the resistors until a negative number is entered.
As you may know formula to calculate total resistance of 2 parallel resistor is
(1/(1/Ra)+(1/Rb))
ofcourse this function should calculate parallel resistance of as many as resistors that are being entered untill a negative number is entered.
I wrote this function but it is not working good, would be nice if you take a look and made some suggestiions or fixitation!
Code:
double R_Parallel(void) {
int nHelp, nCount = 1; // Help and Counter
double fPRE; //Pralaller Resistance Equivelant
double fResistor; //Resistor
while (fResistor >= 0) { //WHILE 1
printf("\nPlease input parallel resistant number %d,
\ninput a negative value to finish the operation: \n", nCount);
scanf("%lf", &fResistor);
//Special case for first resistor
if(nCount == 1) {fPRE = fResistor;};
nCount++;
fPRE = pow(((pow(fPRE, -1))+(pow(fResistor, -1))),-1);
return (fPRE);
}//END WHILE 1
}