Can someone help me out with my Code Coach problem with the ceil function of math.h of C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

6th Feb 2020, 5:54 PM
SSki11
SSki11 - avatar
9 Answers
+ 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.
8th Feb 2020, 7:06 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 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.
8th Feb 2020, 3:28 AM
SSki11
SSki11 - avatar
+ 1
where is your code?
6th Feb 2020, 6:05 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
bahha🐧 wait...
7th Feb 2020, 5:32 PM
SSki11
SSki11 - avatar
+ 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?
7th Feb 2020, 5:43 PM
SSki11
SSki11 - avatar
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.
7th Feb 2020, 6:41 PM
Bahhaⵣ
Bahhaⵣ - avatar
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.
7th Feb 2020, 7:09 PM
Bahhaⵣ
Bahhaⵣ - avatar
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.
8th Feb 2020, 7:03 AM
Bahhaⵣ
Bahhaⵣ - avatar
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
8th Feb 2020, 7:05 AM
Bahhaⵣ
Bahhaⵣ - avatar