Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a function that can be useful for future programs (like the next problem) which rounds any POSITIVE floating point value to the nearest integer.
Write a function that can be useful for future programs (like the next problem) which rounds any POSITIVE floating point value to the nearest integer. The function should "round up"; i.e. fractional parts of 0.5 and above should round to the next higher whole number. The function has the following prototype: int round_to_int(float value); /* Given: a positive float value * Returns: the value rounded to the nearest integer (rounding up) The function is given a positive float value and returns an integer which is the rounded value of its arguement. NOTE: you may have noticed that if you restrict the decimal places printed with %f, printf() rounds to the last decimal place printed - this is NOT what we want here. We want an integer value returned by the function that can be used in future calclulations. Other than debug lines (which you should disable when you turn in your files), your function should not print anything; it should just return the correct integer value. (Hint: to round positive floats you do NOT need an if statement). You will need a main() function to test your round_to_int() function. This main() is called a "test driver", or just "driver". It's sole purpose is to prompt the user for data, one at a time, give the data to the function, and print the result it gets back to let the user check that the function is operating correctly for different input. Your driver should continue to prompt the user until a 0 is entered, when it should terminate. Call the file containing your code round.c. For up to 1 additional bonus point, you can modify your program to work correctly for any float value, positive or negative
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