garryhtreez

6.18

Dec 9th, 2020
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. /*
  2. 6.18 Exponentiation
  3.     Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
  4.     Visual Studio Community 2019
  5. */
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. int integerPower( int base, int exponent ) {
  10.     int value{ 1 };
  11.     for ( int i = 0; i < exponent; i++ ) value *= base;
  12.     return value;
  13. }
  14.  
  15. int main()
  16. {
  17.     int base{ 0 }, exponent{ 0 };
  18.  
  19.     while (true) {
  20.         cout << "Enter base and exponent (in that order) or enter 0 to end: ";
  21.         cin >> base;
  22.         if ( base == 0 ) break;
  23.         cin >> exponent;
  24.         if ( exponent == 0 ) break;
  25.         cout << endl << base << " raised to the power of " << exponent << " equals: " << integerPower( base, exponent ) << endl << endl;
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment