not passing resiststring correctly

The program works great except for passing the Resiststring to the Convertcolor function. The first three band colors are returned as the default (gold). I've looked it over so many times and I can't seem to find the error.
Please excuse any errors in my posting style or etiquette. First time post.

int Resistance::ResistToleranceConvert()
{ string ResistString;
int i(0), C(0), element(0);

ostringstream os;
os << ResistValue;
ResistString = os.str();

while(i < ResistString.length() && element < 3)
{
if (isdigit(ResistString.at(i)))
{
ConvertColor(ResistString.at(i), Band, element);
element++;
}

else if (ResistString.at(i) == '^')
{
if (ResistString.at(i+1) == '-')
{
C = '-' + ResistString.at(i+2);
ConvertColor(C, Band, element);
element++;
}

else
{
C = ResistString.at(i+1);
ConvertColor(C, Band, element);
element++;
}
}
i++;
}

if (ResistValue < 0.01 || ResistValue > 100000000)
return 1;

if (Tolerance == 5)
Band[3] = "Gold";
else if (Tolerance == 10)
Band[3] = "Silver";
else if (Tolerance == 20)
Band[3] = "None";
else
return 2;

return 0;
}


void ConvertColor(char RValue, string Band[4], int element)
{
int Resist;

Resist = int(RValue);

if (Resist == 0)
Band[element] = "black";
else if (Resist == 1)
Band[element] = "brown";
else if (Resist == 2)
Band[element] = "red";
else if (Resist == 3)
Band[element] = "orange";
else if (Resist == 4)
Band[element] = "yellow";
else if (Resist == 5)
Band[element] = "green";
else if (Resist == 6)
Band[element] = "blue";
else if (Resist == 7)
Band[element] = "violet";
else if (Resist == 8)
Band[element] = "gray";
else if (Resist == 9)
Band[element] = "white";
else if (Resist == -1)
Band[element] = "silver";
else
Band[element] = "gold";

return;
}
Please use code tags: [code]Your code[/code]

You can't do that

Resist = int(RValue); // RValue contains the char representation of the number ('0' != 0) ('0' == 48)

So either:

Resist = int(RValue - '0');

or

1
2
if (Resist == '0') // Note ''
etc.


You can also use switch(Resist)
Thanks for the tip on proper posting. I thought the error had to be in Resist = int(RValue); , but I just couldn't see it. Thanks for the help.
Topic archived. No new replies allowed.