+ 2
Can someone help me out with my Code Coach problem with the ceil function of math.h of C++?
IDK why does it happen! There are two Code Coach problems (including the Average Word Length one) I decided to solve using C++ which required me to round up a certain value. I included math.h safely and used the ceil function. But unfortunately, each time my code succeeded in only two cases (first and fourth) and the rest three failed. The expected output in the second case of one of those problems was 5 whereas my code output 3. I even tried with cmath in place of math.h, but everything went in vain. Please help me.
9 ответов
+ 1
that's why some test-cases are hidden.
there are some code coach that can be solved just by guessing the outputs without any operation or input.
+ 2
bahha🐧 But then, why did the first case output correct? If the problem has to be with cin, then every case should output wrong.
+ 1
where is your code?
+ 1
bahha🐧 wait...
+ 1
bahha🐧 Here they are:
https://code.sololearn.com/cItDiimeMwhF/?ref=app
https://code.sololearn.com/cslXHbIS02bu/?ref=app
In 'Halloween Candy' ceil() is working fine; IDK why not in these ones?
0
for Paint you got the tax value wrong it should be 0.1
use printf to set the precision.
printf("%.f",ceil(0.1 * cost + cost));
instead of cout, it's just easier. or look for a c++ way.
0
for Average word...
use getline(cin, input ); instead of cin
because cin stops when it encounters a space.
when you use, cin >> input ; it gets only the first word.
0
coincidence! because the first word is "Can" 3 letters /1 word = 3
test cases are not that smart.
you can just write : cout << 3 ; without any operation and it would pass the first case.
to confirm: just add : cout << input just after cin >> and see the output where the test-cases are shown. 1,2.
one of the most powerful skills in programming is debugging, but it's not taught here.
0
for fun try these codes and see the results :
#include <iostream>
using namespace std;
int main() {
cout << 3;
return 0;
}
---------------------------------
#include <iostream>
using namespace std;
int main() {
cout << 5;
return 0;
}
//try other values to know the hidden cases