Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 6.18 Exponentiation
- Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
- Visual Studio Community 2019
- */
- #include <iostream>
- using namespace std;
- int integerPower( int base, int exponent ) {
- int value{ 1 };
- for ( int i = 0; i < exponent; i++ ) value *= base;
- return value;
- }
- int main()
- {
- int base{ 0 }, exponent{ 0 };
- while (true) {
- cout << "Enter base and exponent (in that order) or enter 0 to end: ";
- cin >> base;
- if ( base == 0 ) break;
- cin >> exponent;
- if ( exponent == 0 ) break;
- cout << endl << base << " raised to the power of " << exponent << " equals: " << integerPower( base, exponent ) << endl << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment