-
Resistances
I have to do a program calculating the total resistance of a ladder network.
I've done the array and what I think is the equation for it. There are no parse errors when I compile it but the program stops after the values have been inputted?
Any ideas?
heres what I have:
#include<iostream.h>
#include<fstream.h>
#include"Array.h"
#include"Text.h"
using namespace std;
int main()
{
Array<double> res;
int NoRes;
double ResVal;
cout << "Welcome to the equivalent resistance calculator." << endl;
cout << "enter the number of resistors in the circuit (must be EVEN number): ";
cin >> NoRes;
res.setSize(NoRes);
cout << endl;
double value;
for (int n=0; n < res.size(); n++)
{
cout << "enter value for resistor " << n+1 << " in ohms : ";
cin >> value;
res(n) = value;
}
ResVal = res(NoRes-1);
for (int i = NoRes-2; i>0; i=i-2)
{
ResVal=ResVal+res(i);
ResVal= (ResVal*res(i-1) / (ResVal + res(i-1))) ;
}
ResVal=ResVal+res(0);
return 0;
}
-
are you sure the program stops ? or does it complete without outputting anything further.
-
Thats what happens when I try to run it! I'm not sure whats going on!
bash 1$ CCCs new.c
bash 2$ a
Welcome to the equivalent resistance calculator.
enter the number of resistors in the circuit (must be EVEN number): 4
enter value for resistor 1 in ohms : 4
enter value for resistor 2 in ohms : 5
enter value for resistor 3 in ohms : 6
enter value for resistor 4 in ohms : 7
bash 3$
-
my point was, and although i dont really know that much about c++. i cant seem to see where you're outputting your calculated resistance
"ResVal = res(NoRes-1);
for (int i = NoRes-2; i>0; i=i-2)
{
ResVal=ResVal+res(i);
ResVal= (ResVal*res(i-1) / (ResVal + res(i-1))) ;
}
ResVal=ResVal+res(0);
cout << ResVal;
return 0;
}"
should perhaps be the amendment, but the chances are im wrong, apologies if thats the case, i only just got up
-
You're so right! Thanks!
Cant believe I forgot that!
Popular pages
Recent additions