As you learned in the chapter, you must be careful

As you learned in the chapter, you must be careful when comparing two real numbers for either equality or inequality because some real numbers cannot be stored precisely in memory. To determine whether two real numbers are either equal or unequal, you should test that the difference between both numbers is less than some acceptable small value, such as 0.00001. 

a. Start your C++ development tool, and view the Advanced16.cpp file. The file is contained in either the Cpp8Chap05Advanced16 Project folder or the Cpp8Chap05 folder. (Depending on your C++ development tool, you may need to open this exercise’s solution/project file first.) The code divides the contents of the num1 variable (10.0) by the contents of the num2 variable (3.0), storing the result (approximately 3.33333) in the quotient variable. An if statement is used to compare the contents of the quotient variable with the number 3.33333. The if statement displays a message that indicates whether the numbers are equal. 

b. Run the program. Even though the message on the screen states that the quotient is 3.33333, the message indicates that this value is not equal to 3.33333. Close the Command Prompt window. 

c. If you need to compare two real numbers for equality or inequality, first find the difference between both numbers, and then compare the absolute value of that difference to a small number, such as 0.00001. The absolute value of a number is a positive number that represents the distance the number is from 0 on the number line. For example, the absolute value of the number 5 is 5, and so is the absolute value of the number –5; both numbers are an equal distance from 0 on the number line. You can use the C++ fabs function to find the absolute value of a real number; however, your program must contain the #include  directive. Modify the program appropriately. Save and then run the program. This time, the message “Yes, the quotient 3.33333 is equal to 3.33333.” appears.

How Our Website Works

1. FILL IN OUR SIMPLE ORDER FORM

It has never been easier to place your order. Fill in the initial requirements in the small order form located on the home page and press “continue” button to proceed to the main order form or press “order” button in the header menu. Starting from there let our system intuitively guide you through all steps of ordering process.

2. PROCEED WITH THE PAYMENT

All your payments are processed securely through PayPal. This enables us to guarantee a 100% security of your funds and process payments swiftly.

3. WRITER ASSIGNMENT

Next, we match up your order details with the most qualified freelance writer in your field.

4. WRITING PROCESS

Once we have found the most suitable writer for your assignment, they start working on a masterpiece just for you!

5. DELIVERY

Once finished, your final paper will be available for download through your personal dashboard. You will also receive an email notification with a copy of your paper attached to it. Sometimes, the writer may leave a note for you about the order in case there is any additional information that they need to give you.

Leave a Reply

Your email address will not be published.