I am doing an exercise and I have to make a program that uses the funtion floor() to round a decimal down to the nearest integer.
I have never used floor() before but I am aware it is in the <cmath> header. After doing a bit of online searching on it I discovered it takes and returns and double value.
This is what I have done but I am getting an identical output each time and the function is not working. If I attempt to change anything to an int I get a warning about "possible loss of data".
Can anyone offer my any advice?
Code:#include <iostream> #include <iomanip> #include <cmath> // function prototype double roundToInteger ( double ); // main function - driver ////////////////////////////////////////////////////// // int main ( void ) { std::cout << std::setprecision( 2 ) << std::fixed; for ( double i = 1.0; i <= 10.0; i++ ) { std::cout << i << " rounded is: " << roundToInteger ( i ) << std::endl; } std::cin.get(); // freeze console output window return 0; // return value from int main } // function that rounds and returns the passed // value to the nearest integer double roundToInteger ( double num ) { double x = 0; x = floor ( num ); return x; }