I have been trying to solve a problem that requires me to round a whole number integer and add up the 3 integers. The problem being that if the integers most right digit is 5 or higher it rounds to 10.Another would be 15 or higher it would round to 20. Also, the number range of 0 through 4 will be 0 and the the range of 10 through 14 will be 10. There is also a catch to it; which is that you can't change anything out of the "Enter your code area" area. First, I had the idea of using the if statement and have it search the numbers range but the output was off and the code was long, so I stopped. Then I thought of doing this static_cast<int>((a * 0.1) % 1); but was unable to compile. So, if anyone could give a beginner some advice or hints I would be very grateful and Thanks in advance.
#include <iostream>
using namespace std;
int main()
{
cout << "Enter three integers: ";
int a, b, c;
cin >> a >> b >> c;
you can round (not whole) numbers down, by converting floats to integers.
if you first add 0.5 to float it will be rounded the right way. for example 1.6+0.5=2.1, 2.1 rounds down to 2. 1.4+0.5=1.9, 1.9 rounds down to 1. to round a whole number you should first convert it to float (multiply by 0.1), then add 0.5, convert to integer and finally multiply it by 10.