void main double number convergentvalue int

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /////////////////////////////////////////////// #include <iostream> using namespace std; double queryUserForValue(); void computeSeries(double x, double &sum, int &nbrLoops); void outputResults(double result, int iterations); // The main function coordinates the retrieval of the value to be used in the power // // series, the calculation of the series limit, and the output of the results. // void main() { double number, convergentValue; int nbrIterations; number = queryUserForValue(); computeSeries(number, convergentValue, nbrIterations); outputResults(convergentValue, nbrIterations); return; } // This function queries the user for the power series // // generator value, which must be strictly between 0 and 1. // double queryUserForValue() { double nbr; cout << "Enter the number to be tested: "; cin >> nbr; while ((nbr <= 0.0) || (nbr >= 1.0)) { cout << "The number must be greater than 0 and less than 1." << endl << "Enter the number to be tested: "; cin >> nbr; } return nbr; } CS 140 Chapter 4 Page 10 // This function repeatedly adds the next power of the generator value to the series expansion, // // until two consecutive sums are equal, at which time the series is considered to converge. // void computeSeries(double x, double &sum, int &nbrLoops) { double powerOfX, p...
View Full Document

This note was uploaded on 08/26/2009 for the course CS 140 taught by Professor Staff during the Fall '08 term at Southern Illinois University Edwardsville.

Ask a homework question - tutors are online