1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <iostream>
using namespace std;
double RParallel (double, double, double=1e12, double=1e12, double=1e12);
int main ()
{
double r1, r2, r3, r4, r5;
int amt;
double res;
cout<<"Please enter the number of resistors in the parallel circuit (between 2 and 5): ";
cin>>amt;
if (amt<2 || amt>5)
{
cout<<"\nIncorrect number of resistors, try again."<<endl;
system ("pause");
return 0;
}
if (amt==2)
{
cout<<"\nEnter the values for the resistors:"<<endl;
cin>>r1>>r2;
cout<<"\nThe resistor values are ( "<<r1<<" "<<r2<<" )"<<endl;
res=RParallel (r1, r2);
cout<<"The parallel resistance is: "<<res<<endl;
}
if (amt==3)
{
cout<<"\nEnter the values for the resistors:"<<endl;
cin>>r1>>r2>>r3;
cout<<"The resistor values are ( "<<r1<<" "<<r2<<" "<<r3<<" )"<<endl;
res=RParallel (r1, r2, r3);
cout<<"The parallel resistance is: "<<res<<endl;
}
if (amt==4)
{
cout<<"\nEnter the values for the resistors:"<<endl;
cin>>r1>>r2>>r3>>r4;
cout<<"The resistor values are ( "<<r1<<" "<<r2<<" "<<r3<<" "<<r4<<" )"<<endl;
res=RParallel (r1, r2, r3, r4 );
cout<<"The parallel resistance is: "<<res<<endl;
}
if (amt==5)
{
cout<<"\nEnter the values for the resistors:"<<endl;
cin>>r1>>r2>>r3>>r4>>r5;
cout<<"The resistor values are ( "<<r1<<" "<<r2<<" "<<r3<<" "<<r4<<" "<<r5<<" )"<<endl;
res=RParallel (r1, r2, r3, r4, r5);
cout<<"The parallel resistance is: "<<res<<endl;
}
system("pause");
return 0;
}
double RParallel (double r1, double r2, double r3, double r4, double r5)
{
return 1.0/((1.0/r1)+(1.0/r2)+(1.0/r3)+(1.0/r4)+(1.0/r5));
}
|