I’m learning C++ now and im following a tutorial made by BroCode.
Anyways. He’s talking about how these functions should output a rounded number but it doesn’t do it in my programm
#include <iostream>
#include <cmath>
int main(){
double x = 3;
double y = 4;
double pi = 3.14;
double z;
z = round(pi);
std::cout << pi << 'n';
z = ceil(pi);
std::cout << pi << 'n';
z = floor(pi);
std::cout << pi << 'n';
return 0;
}
3.14 is the output for all 3 of those functions.
5
std::round
, std::ceil
, and std::floor
do not modify the variable passed to them. They return the rounded, ceilinged, or floored value as their result. That means that in your example, pi
remains unchanged, but z
will be either 3
or 4
depending on the operation done.