ROUND OFF

How to create a program using user-defined function that converts a number with decimal points that you will input to a whole number without using the function round()
Study your class notes. Look at the examples in your textbook and online. Give it a try.

Come back if/when you are stumped because something didn't work the way you expected.
This is my code and it is working. Thank you for telling me to give it a try again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <cmath>
using namespace std;

float roundoff (float decimals)
{
	int result = (int)(decimals + 0.5f);
	return result;
}

int main ()
{
	float decimal;
	
	cout << "Input a number with decimal point: ";
	cin >> decimal;
	
	float result = roundoff (decimal);
	
	cout << "Rounding it off to whole number: " << result << "\n";
	
	return 0;
}

Try it with -0.9
Topic archived. No new replies allowed.