Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prompt the user for two integers. The program then calculates the sum of the integers, the difference of the integers, the product of the integers,

image text in transcribed

Prompt the user for two integers. The program then calculates the sum of the integers, the difference of the integers, the product of the integers, and the quotient with remainder of the integers. All of these math calculations are performed in one function. But how can a function return more than one value? By using formal parameters that are reference variables. In other words, pass the parameters by reference. 1. getData() - A void-returning function. - The function prompts the user for two integer values. - The function receives two integer arguments passed by reference to hold the values entered by the user. 2. doTheMath() - A void-returning function adds, subtracts, multiplies, and divides the two integers as described above. - The function receives 7 arguments: a.) num1 - The first integer value from the user (pass by value). b.) num2 - The second integer valuea from the user (pass by value). c.) sum (pass by reference) d.) difference (pass by reference) e.) product (pass by reference) f.) quotient (pass by reference) g.) remainder (pass by reference) 3. displayResults() - A void-returning function displays the results of the four math operations. - The function receives the 7 arguments. - The arguments are passed in the same manner as described in #2. Potential problem: If the user enters a value of zero for the second number, a problem arises with division (cannot divide by zero). - If you don't handle the situation, your program will crash because the CPU will not allow division by zero. Solution: Include code to prevent division by zero. If the second number is zero, then output should state: "Cannot divide by zero." /* Output when num2 != 0: /* Output when num2 = 0: Please enter two integer values: This statement is in the getData() function. 12 Here are the results: The sum of 12 and 3 is 15. The difference, (12 minus 3) is 9. The product of 12 and 3 is 36. 12 divided by 3 is 4 with a remainder of 0. These statements are in the displayResults() function Please enter two integer values: 9 0 Here are the results: The sum of 9 and 0 is 9. The difference, (9 minus 0) is 9. The product of 9 and 0 is 0. Cannot divide by zero. Press any key to continue */

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

Will we be able to keep up with company growth?

Answered: 1 week ago

Question

Q.No.1 Explain Large scale map ? Q.No.2 Explain small scale map ?

Answered: 1 week ago

Question

1. Signs and symbols of the map Briefly by box ?

Answered: 1 week ago

Question

Types of physical Maps?

Answered: 1 week ago