Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using C++ Define the following constants: const int FLOOR_ROUND = 1; const int C

ID: 3751648 • Letter: U

Question

using C++ Define the following constants: const int FLOOR_ROUND = 1; const int CEILING_ROUND = 2; const int ROUND = 3; Write a program that asks the user to enter a Real number, then it asks the user to enter the method by which they want to round that number (floor, ceiling or to the nearest integer). The program will then print the rounded result. Your program should interact with the user exactly as it shows in the following example: Please enter a Real number: 4.78 Choose your rounding method: 1. Floor round 2. Ceiling round 3. Round to the nearest whole number 2 5 Implementation requirement: Use a switch statement.

Explanation / Answer


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double input;
int choice;
cout << "Please enter a real number: ";
cin >> input;
cout << "Choose a rounding method" << endl;
cout << "1. Floor round" << endl;
cout << "2. Ceiling round" << endl;
cout << "3. Round to nearest whole number" << endl;
cin >> choice;
switch(choice)
{
case 1:
cout << "Output: " << floor(input) << endl;
break;
case 2:
cout << "Output: " << ceil(input) << endl;
break;
case 3:
cout << "Output: " << round(input) << endl;
break;
default:
cout << "Invalid choice" << endl;
}
}

output
-----
Please enter a real number: 4.78
Choose a rounding method
1. Floor round
2. Ceiling round
3. Round to nearest whole number
2
Output: 5
Please enter a real number: 2.3
Choose a rounding method
1. Floor round
2. Ceiling round
3. Round to nearest whole number
3
Output: 2