New to c++ ,paint costs code coach | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

New to c++ ,paint costs code coach

#include <iostream> #include <math.h> using namespace std; int main() { int a; cin>>a; cout <<round((40+5*a)*1.1); return 0; } Failing in last test case ( In python I did the same way and passed)

4th Nov 2021, 6:24 AM
Prabhas Koya
3 Answers
0
Prabhas Koya It returns integral value but as a floating-point value but need as a integer so we need to cast with int or you can assign result to int then print int value. int d = round((40 + 5 * a) * 1.1); cout << d; here is round function in c++: double round (double x); float round (float x); long double round (long double x); double round (T x);
4th Nov 2021, 9:20 AM
A͢J
A͢J - avatar
+ 2
Prabhas Koya Cast with int cout << int(round((40 + 5 * a) * 1.1));
4th Nov 2021, 6:34 AM
A͢J
A͢J - avatar
+ 1
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Doesn't round produce an integral value
4th Nov 2021, 6:59 AM
Prabhas Koya