Question
in c++ Write a program that calculates the floor of a decimal number, Basically the Floor of any decimal number x, is the nearest whole
in c++
Write a program that calculates the floor of a decimal number,
Basically the Floor of any decimal number x, is the nearest whole number less than or equal to x.
For example, the floor of 2.4 is 2.0. The floor of 4.2 is 4.0. The floor of -23.1 is -24. The floor of 9.0 is 9. The floor of -10.0 is -10.0.
Requirements
1) You must implement a function to calculate the floor (you cannot use C++'s floor function). Name it floorAndError).
2) The program will ask the user to input a number (let's call this variable userInput)
3) The number will be passed to floorAndError by Reference
4) The function should change the userInput variable to the nearest whole number less than or equal to the original value of userInput that was inputted by the user. Therefore if the user inputted 4.3 into the variable userInput, after the function runs userInput will have the value 4.0. (note if the user enters -4.3 the floor is actually -5, think about how you might do this)
5) The function should return how much the value was changed by, i.e., the difference the new value of userInput and the old value of userInput. SO if the user inputted 4.3 the function will return a value equal to 4.0-4.3= .3
6) The program should define the function prototype above main and the function definition after main
7) All the program input and output should occur in main
8) The function comments must have a pre condition and post condition both at the function prototype and the function definition
9) All the rest of the code should include comments too
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started