//File: .../code/tableOfPowers.cp // //modifies Listing 2.10, p. 47 [Cannon] to use simple functions #include #include //for setw() /* printHeadings() -------------------------------------------------------- * prints headings for table */ void printHeadings() { cout <<" Table of Powers" << endl << endl; cout << " N 2 3 4 5 6" << endl; } /* printSixPowers() ------------------------------------------------------- * display first six powers of n on current line */ void printSixPowers(int n) { int power = 1; // power of n int count = 1; // loop var //print six powers of n while(count <= 6){ power = power * n; count++; cout << setw(7) << power; } cout << endl; } /* main() ----------------------------------------------------------------- */ void main() { int n = 1; // build table of powers of n printHeadings(); while(n <= 5){ printSixPowers(n); n++; } }