+ 1
The question asks you to round up the answer to the nearest whole number. I've used round() but my ans is 66 instead of 67
#include <iostream> #include <cmath> using namespace std; int main() { int houses; cin>>houses; int a ; a = 200 / houses ; cout << round(a) ; return 0; }
4 Réponses
+ 6
Kruti
Have you also changed one of the operand ( 200 or houses ) to double/float ?
If yes then try using ceil () instead to round UP floating point number.
https://en.cppreference.com/w/c/numeric/math/ceil
+ 4
double a = 200.0 / houses.
round() doesn't help if you define <a> as `int`, cause `int` doesn't care about fractionals, there is no decimal point to consider for rounding the number.
+ 2
Arsenic thank you so much! I tried ceil() yesterday but didn't use double houses. It is correct now.
+ 1
Ipang I tried with double a. Still the answer is 66.
How do I round it up to the largest number? Right now 66.3 is rounded off as 66 but the question asks to round it off as 67