Anyone have any idea how to convert this psuedo code to c++
1 2 3 4 5 6 7 8 9 10 11 12
Function roundValue(Declare value, decimalPlaces)
i = 0
magnitude = 1
FOR i = 0 To decimalPlaces
magnitude = magnitude * 10
END FOR
value = value * magnitude
value = (int,value + 0.5)
value = value / magnitude
return value
END FUNCTION
http://www.cplusplus.com/doc/tutorial/functions/ Ive been through this, still doesnt make it any clearer for me. I dont expect you do it, can someone just make it clearer or point me in right direction, im so confused
//Function roundValue(Declare value, decimalPlaces)
double round_value( double value, int decimal_places )
{
//i = 0
//magnitude = 1
int magnitude = 1 ;
//FOR i = 0 To decimalPlaces
for( int i = 0 ; i < decimal_places ; ++i )
magnitude = magnitude * 10 ;
//END FOR
value = value * magnitude ;
//value = (int,value + 0.5)
value = int( value + 0.5 ) ;
value = value / magnitude ;
return value ;
//END FUNCTION
}
Another go that doesnt work.
float roundvalue(float value, int DecimalPlaces);
int magnitude=1;
magnitude=magnitude*10;
value=value*magnitude
value=(int)value+.5)
value=value/magnitude);