When I compile the included code with the Borland c++ 5.5 command line tools I get the error:
Why?C:\BC45\bob>bcc32 over1.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
OVER1.CPP:
Error E2015 OVER1.CPP 13: Ambiguity between 'std::abs(int)' and 'abs(int)' in fu
nction main()
Warning W8004 OVER1.CPP 20: 'i' is assigned a value that is never used in functi
on main()
*** 1 errors in Compile ***
Also, when I compile it with Borland C++ 4.5 it rounds 64.53 upto 65 when instead it should output 64.53. Isn't setprecision() used for specifying how many decimal places you want? Like in C you could say printf("%.2f");.
Code:#include <iostream> #include <iomanip.h> int abs(int i); float abs(float x); int main() { int ians; float fans; int i = -15; float x = -64.53; ians = abs(i); cout << "Integer absolute value of -15 is " << ians << endl; fans = abs(x); cout << "Float absolute value of -64.53 is " << setprecision(2) << fans << endl; cin.get(); return 0; } int abs(int i) { if(i < 0) return(i * -1); else return (i); } float abs(float x) { if(x < 0.0) return(x * -1.00); else return (x); }