the judge is saying this is wrong ! i can’t find the error. please help ! thanks.
http://www.codechef.com/viewsolution/3201220
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{int x;
float y;
cin>>x>>y;
if(x%5==0 && x<=(y-0.5))
y=y-x-0.50;
cout<<setprecision(2)<<y;
}
print x also,it may be work
r3gz3n
January 7, 2014, 2:03am
3
its giving wrong answer for 3 120.00…try setprecision(6)…
Try removing ‘=’ …x<y-0.5
std::fixed is-
ios_base& fixed (ios_base& str);
It sets the floatfield format flag for the str stream to fixed.
When floatfield is set to fixed, floating-point values are written using fixed-point notation: the value is represented with exactly as many digits in the decimal part as specified by the precision field (precision) and with no exponent part.
you can write-
cout << setiosflags(ios::fixed | ios::showpoint)
<< setprecision(2)
<< y;
for more details refer to-
http://www.cplusplus.com/reference/ios/fixed/
1 Like
i have resolved this partially. It worked if i add cout<<fixed; before the orignal cout statment.but I have no idea how!
no output needs only y-balance. x is withdraw amt is not needed
no ,I rechecked output is 120 only for 3.set precision is way too high . the question only wants 2 digits of precision.