Fe nce this function outputs the power series final

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: reviousSum = 0.0; nbrLoops = 0; sum = x; powerOfX = x; while (previousSum < sum) { nbrLoops++; previousSum = sum; powerOfX *= x; sum += powerOfX; } return; } This function has thre param te e e rs. Thefirst param te is thevaluee re by theuse which won't be e r nte d r, change in this function, so it's passe by value d d . These cond and third param te arevalue be calculate in this e rs s ing d function; the ne de in thecalling function, so the passe by y're e d y're d re re . fe nce // This function outputs the power series final value, as // // well as the number of iterations required to obtain it. // void outputResults(double result, int iterations) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(8); cout << "The series converges to " << result << " in " << iterations << " iterations." << endl << endl; return; } CS 140 Chapter 4 Page 11 Nested Functions #include <iostream> #include <iomanip> #include <cmath> using namespace std; Just like main, any function may contain a call to another function within its body. double queryUserForValue(); bool testValueBounds(double value); void outputWarning(double value); void generateResults(double val, double &sinVal, double &cosVal, double &logVal); void outputResults(double val, double sinVal, double cosVal, do...
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