# Trying Compare User Inputed Resistance Tolerance Find Closest Value Standard Eia Values Al Q12684675

I am trying to compare an user inputed resistance andtolerance, and find the closest value from the standard EIA valueswhich i already created in arrays. After determining the standardEIA value, i want to input that information back to the user. Theinformation should include the Closest standard resistance, and the4 color bands needed to make that resistance. My idea was to usethe resistance to color function that has been tested to work, andthen send those colors into the new function StandardRes, im whichi could test band 1 + band 2 ‘s value through the inputed tolerancerange. Once it goes through the for loop from the tolerance, Ithought it would set equal to one of the nominal values in thearray , then i would multiply band 3 to the end of the new value.C++

using namespace std; //introduces namespace std
//EIA Standard array element sizes per tolerance class
const int E12 = 12;  // 10% tolerance
const int E24 = 24;    // 5% tolerance
const int E6 = 6;   // 20% tolerance

const int nominalE12values[E12]={10, 12, 15, 18, 22, 27,33, 39, 47, 56, 68, 82};  // 10% tolerance
const int nominalE24values[E24]={10,11,12, 13, 15, 16, 18, 20, 22,24, 27, 30,
33, 36, 39, 43,47, 51, 56, 62, 68, 75, 82, 91} ;    // 5%tolerance
const int nominalE6values[E6]={10, 15, 22, 33, 47,68};          // 20%tolerance

class Resistance
{
private:
double resValuee;
int tolValueee;
stringcband1,cband2,cband3,cband4;

public:
intcolorToResistancee(string,string,string,string,double&,int&);  //memberfunctions
intStandardRes(string&,string&,string&,string&,double&,int&);
int ResistanceToColor(double,int,string &, string &, string &, string &);
voidmaxminResistancee(double&,double&);

int main()

*assume variable below are declared

{

cout<<“Please enter the desired resistance value inohms: “;
cin >> rr;
cout<< endl;
cout<<“Please enter the desired tolerance as apercentage (5, 10, or 20): “;
cin >> tt;
resistor.ResistanceToColor(rr,tt,bA,bB,bC,bD);
resistor.StandardRes(bA,bB,bC,bD,rr,tt);
cout<< endl;
cout << “Closest Standard Resistance: ” <<fixed << setprecision(0) << rr << ” ohms “<< endl;
cout<<“Color Band A: “<< bA <<endl;
cout<<“Color Band B: “<< bB <<endl;
cout<<“Color Band C: “<< bC <<endl;
cout<<“Color Band D: “<< bD <<endl;

}

int Resistance::StandardRes(string &b1 ,string&b2, string &b3, string &b4, double &resR, int&tolR)
{
cband1 = b1;
cband2 = b2;
cband3 = b3;
cband4 = b4;
if ( cband2 == “black” ) resValuee = 0;
if ( cband2 == “brown” ) resValuee = 1;
if ( cband2 == “red” ) resValuee = 2;
if ( cband2 == “orange” ) resValuee = 3;
if ( cband2 == “yellow” ) resValuee = 4;
if ( cband2 == “green” ) resValuee = 5;
if ( cband2 == “blue” ) resValuee = 6;
if ( cband2 == “violet” ) resValuee = 7;
if ( cband2 == “gray” ) resValuee = 8;
if ( cband2 == “white” ) resValuee = 9;
else return 2;
if ( cband1 == “black” );
if ( cband1 == “brown” ) resValuee += 10;
if ( cband1 == “red” ) resValuee += 20;
if ( cband1 == “orange” ) resValuee += 30;
if ( cband1 == “yellow” ) resValuee += 40;
if ( cband1 == “green” ) resValuee += 50;
if ( cband1 == “blue” ) resValuee += 60;
if ( cband1 == “violet” ) resValuee += 70;
if ( cband1 == “gray” ) resValuee += 80;
if ( cband1 == “white” ) resValuee += 90;
else return 1;
if ( cband4 == “gold” )
{
tolValueee = 5;
for(int i=1 ; i<25 ; i++)
{
if(resValuee == nominalE24values[i])
{
resValuee=nominalE24values[i];
}
if(resValuee == nominalE24values[i-1])
{
resValuee=nominalE24values[i-1];
}
if(resValuee>nominalE24values[i-1] &&resValuee<nominalE24values[i])
{
resValuee=nominalE24values[i-1];
}
}
}
if ( cband4 == “silver” )
{
tolValueee = 10;
for(int i=1 ; i<13 ; i++)
{
if(resValuee == nominalE12values[i])
{
resValuee=nominalE12values[i];
}
if(resValuee == nominalE12values[i-1])
{
resValuee=nominalE12values[i-1];
}
if(resValuee>nominalE12values[i-1] &&resValuee<nominalE12values[i])
{
resValuee=nominalE12values[i-1];
}
}
}
if ( cband4 == “none” )
{
tolValueee = 20;
for(int i=1 ; i<7 ; i++)
{
if(resValuee == nominalE6values[i])
{
resValuee=nominalE6values[i];
}
if(resValuee == nominalE6values[i-1])
{
resValuee=nominalE6values[i-1];
}
if(resValuee>nominalE6values[i-1] &&resValuee<nominalE6values[i])
{
resValuee=nominalE6values[i-1];
}
}
}
else return 3;
if ( cband3 == “black” );
if ( cband3 == “brown” ) resValuee *= 10;
if ( cband3 == “red” ) resValuee *= 100;
if ( cband3 == “orange” ) resValuee *=1000;
if ( cband3 == “yellow” ) resValuee *=10000;
if ( cband3 == “green” ) resValuee *=100000;
if ( cband3 == “blue” ) resValuee *= 1000000;
if ( cband3 == “violet” ) resValuee *= 10000000;
if ( cband3 == “gray” ) resValuee *= 100000000;
if ( cband3 == “white” ) resValuee *= 1000000000;
if ( cband3 == “silver” ) resValuee *=0.1;
if ( cband3 == “gold” ) resValuee *= 0.01;
resR = resValuee;
tolR = tolValueee;
return 0;
}

here is an example of the test output that i shouldrecieve:

"We Offer Paper Writing Services on all Disciplines, Make an Order Now and we will be Glad to Help"
0 replies