: by formula (s=a/1-r), and by adding the individual terms until the answer agrees with the formula to 7 significant digits. The print the formula answer, the answer found by adding terms, and the number of terms that were added. Print the sums to at least ten places. Verify input with a while loop. Two real values are equal to n significant digits if the foll

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 38SA
icon
Related questions
icon
Concept explainers
Question
100%

write a program that will add the terms of an infinite geometric series
The program should read the first term (a) and the common ratio (r) for the series. It should the compute the sum in two ways: by formula (s=a/1-r), and by adding the individual terms until the answer agrees with the formula to 7 significant digits. The print the formula answer, the answer found by adding terms, and the number of terms that were added. Print the sums to at least ten places. Verify input with a while loop. Two real values are equal to n significant digits if the following condition is true: |a-b|<|a*10^-n| c++.PLEASE EXPLAIN CODE HELP ME.

1. Read first term and common ratio.
2. Make sure the common ratio is valid.
3. Compute the sum of the series using
the formula.
4. Write a while loop to compute the sum
by adding terms of the series until it
agrees with the formula sum to seven
significant digits, counting the number of
terms it takes.
5. Print the formula answer, the answer
by adding terms, and the number of terms
that were added.
Finally print the results. I would use cout.precision(10), but I would not set fixed or
scientific notation. Good luck!
Transcribed Image Text:1. Read first term and common ratio. 2. Make sure the common ratio is valid. 3. Compute the sum of the series using the formula. 4. Write a while loop to compute the sum by adding terms of the series until it agrees with the formula sum to seven significant digits, counting the number of terms it takes. 5. Print the formula answer, the answer by adding terms, and the number of terms that were added. Finally print the results. I would use cout.precision(10), but I would not set fixed or scientific notation. Good luck!
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning