Question: Write a program with two functions: main (as usual) and a function called decimal that will return the decimal part of any non-negative decimal number

  1. Write a program with two functions: main (as usual) and a function called decimal that will return the decimal part of any non-negative decimal number sent to it as input. For example, a call like: decimal(3.7) should return 0.7 It should be clear that function decimal will have to return a double, and will have to accept a parameter of type double. Define the function so that its return type and parameter type are consistent with the above description. Your program should prompt the user in main to enter a decimal number, and then call function decimal to separate the decimal portion and return the resulting double, a value that main will display. You can separate the decimal part by subtraction if you create a truncated version of the original decimal number. You can truncate a decimal into an int by casting it to int or by type coercion (search this term in the book or Google it). The goal of this exercise is to become more familiar with the use of functions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!