### Can anyone convert this psuedo function code to c

Anyone have any idea how to convert this psuedo code to c++

 ``123456789101112`` `````` 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``````
Did you even try?
yes, And I failed miserably, I have another thread up, I tried to convert it... Its just not clicking for me... Not sure why
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
float roundvalue(int value, int DecimalPlaces,);
i=0;
magnitude = 1;
for(i=0;i=DecimalPlaces;i++)
{
magnitude = magnitude *10
}
value = value*magnitude
value=(int)value+.5)
value=value/magnitude)

here was one attempt, close?
 ``1234567891011121314151617181920212223`` ``````//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);
 ``12345678910111213141516171819202122`` ``````//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 ``````

Hi, would i need to declare the i as an int before this? or its not needed?
for( int i

or is that declaring it there?, didn't realise you could do that
I put this into my code.

 ``1234567891011121314`` `````` /*Round each number*/ double round_value(double value, int decimal_places) { int magnitude = 1; for (int i=0 ;i=decimal_places;i++) { magnitude=magnitude*10; } value=value*magnitude; value=int ( value +.5); value = value/magnitude; return value; }``````

But im getting an error on my first {, it says it expected a ";", when i put one decimal_places);, u get a load more errors through the code.
 ``12345678910`` ``````double roundValue(double value, int decimalPlaces) { double magnitude=1.0; for(unsigned int i=0; i
Thanks for your response, its still giving me an error on the first {

(error C2601: 'round_value': local function definitions are illegal)
Bump, anyone?
It seems as though you are doing something like this:

 ``1234567`` ``````int main(int argc, char* argv[]) { double round_value(double value, int decimalplaces) { //... } return 0; }``````

Which is illegal.
Topic archived. No new replies allowed.