Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

What is the speed of sound in air at (a) 10oC and (b) 20oC?

Answered: 1 week ago

Question

4. What action should Cherita Howard take and why?

Answered: 1 week ago