getting wrong calculations from function.

this is part of a class and the resistor and tolerance have been set to 1000 and 10 respectivley and for some reason it keeps setting Rmax and Rmin to 1000 it should be setting then to 1100 and 900 any hints on why its not?

1
2
3
4
5
6
  void cResistor2::setMaxnMin()
{
	Rmax = (resistor * (1 + tolerance / 100));

	Rmin = (resistor - (resistor * (tolerance / 100)));
}





Thanks i have been trying to figure it out all night yeah the resistor and tolerance are int didnt' even click that the decimal drops ty all
Last edited on
What are the types for the variables resistor and tolerance? Do you have them as int?

If so, realise what happens with integer division: 10/100 is zero.

Make your types double.

Hope all is well.
You should refer to class members in member functions by the built-in pointer this, which points to the current instance of the class.

aka:

operator=() for a resistor (this is psuedocode):
1
2
3
4
5
6
7
cResistor2& cResistor2::operator=(const cResistor2& resist)
{
    this->current = resist.current;
    this->voltage = resist.voltage;
    this->amp = resist.amp;
    return *this;
}


by doing this, you can directly change the values of members of a class from within the class.
is Rmaz and Rmin double , i don't see any problems

EDIT: i'm sorry i mean tolerance and resistor :)))
Last edited on
It's only the type of tolerance that counts.
Last edited on
Topic archived. No new replies allowed.