looking for this equivalent functions in c++
in pascal you just write round x or abs x and outputs what u want
im searching like half an hour the msdn found something for abs but its of type int abs( int n );
looking for this equivalent functions in c++
in pascal you just write round x or abs x and outputs what u want
im searching like half an hour the msdn found something for abs but its of type int abs( int n );
I'm not sure bout rounding but for abs:
#include <math.h>
#include <iostream.h>
#include <stdlib.h>
int main() {
int number = -5;
cout << abs(number);
system("PAUSE");
return 0;
}
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
There is ceil() and floor(); and setprecision(); and of course truncation, but I don't know of a standard rounding function. I've seen some 3rd party versions that don't look to tough to write, so give a shot yourself and see what you come up with
isnt that weird a whole prog. language like c++ doesnt have a
predifined function for round
anyways ill try something out
hehehe
to round to nearest int....
int Round( double in)
{
return (floor (in+0.5));
}
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
int rounding( float y,float yaxis)
{
double a;
char &buffer;
int decimal,sign;
a = (y+10)/yaxis;
buffer = _fcvt( a, 0 , &decimal , &sign );
return buffer;
};
well after doing some research in the msdn i found this and modified and made this function
but i get an error
cannot convert from 'char *' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
ok boys i managed thx to the last guy for the help
int round(float y, float yaxis)
{
double in;
in = (y+10)/yaxis;
return (floor (in+0.5));
};