Approximation



int x =1.7 + 3;

std::cout<<x; //this will print 4.7 as the value of x, how do I make the program print 5 as the approximate value of x?
http://www.cplusplus.com/reference/cmath/round/

EDIT: Also, since x is an int in your example, it would actually print 4.
Last edited on
Oh my bad..


double x =1.7 + 3;
std::cout<<x; //this will print 4.7 as the value of x.

int y = ceil(x);
std::cout<<y; //this prints 5 as the value of x.


thanks @fg109, that was helpful
Topic archived. No new replies allowed.