Title description
Write a program that accepts a positive floating-point value and outputs an approximate integer value of that value. If the value after the decimal point is greater than or equal to 5, round up; if it is less than 5, round down.
Enter description:
Enter a positive floating point value
Output description:
Output approximate integer value of this value
Example 1
Input
5.5
Output
6
#include <iostream>
using namespace std;
int approxi(float n){
if(int(n * 10) % 10 >= 5) return int(n) + 1;
else return int(n);
}
int main(){
float n;
cin >> n;
cout << approxi(n) << endl;
return 0;
}