0
Error in Code coach task (c++)
In paint cost this code passes all first 4 cases but not last one. What is the error in it I tried using ceil and round function but of no luck. https://code.sololearn.com/cIj8uBtyZkO9/?ref=app
8 Antworten
+ 4
#include <iostream>
#include <math.h>
using namespace std;
int nearest(float f){
return ((f-(int)f)>=0.5) ? ceil(f) : floor(f);
}
int main() {
float p,cb,t;
cb=40;
cin>>p;
p*=5;
t=(p+cb)*0.1;
cout<<nearest(p+t+cb);
return 0;
}
+ 2
Your line 11 is wrong(i mean rounding is wrong)
+ 2
Sanjyot21
This is what I meant
int main() {
...redacted
}
+ 1
Just make p and cb an int. t should be a float. Then calculate t, round up and convert t to an int and add p and cb.
+ 1
Rohit thanks bro
+ 1
ChaoticDawg Ya ok sorry my mistake. Thanks
0
You don't have to always go for the ceil value, because in question it is written round off value
0
ChaoticDawg I tried your suggestion but gave error. Anyways thanks for your response.