Write a C++ program that uses the statements to calculate x raised to the y power. The program should have a while iteration statement.

```
// Exercise 4.8 Solution: power.cpp
// Raise x to the y power.
#include
using namespace std;

int main() {
unsigned int i{1}; // initialize i to begin counting from 1
unsigned int power{1}; // initialize power

cout << "Enter base as an integer: "; // prompt for base
unsigned int x; // base
cin >> x; // input base

cout << "Enter exponent as an integer: "; // prompt for exponent
unsigned int y; // exponent
cin >> y; // input exponent

// count from 1 to y and multiply power by x each time
while (i <= y) {
power *= x;
++i;
} // end while

cout << power << endl; // display result
} // end main
```


Enter base as an integer: 2
Enter exponent as an integer: 3
8

Computer Science & Information Technology

You might also like to view...

The ________ element displays a collection's data in tabular format.

a. h:table. b. h:collection. c. h:dataTable. d. None of the above.

Computer Science & Information Technology

The _________________, which is the latest of the RSA schemes, is the one that RSA Laboratories recommends as the most secure of the RSA schemes.

A. RSA-PSS B. ECDSA C. DSA-SDS D. EDSDS

Computer Science & Information Technology

The RPM utility is closed source software licensed by Red Hat, Inc.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

What is the next Fibonacci number in the following sequence?1, 1, 2, 3, 5, 8, 13, 21, ...

A. 34 B. 43 C. 56 D. 273

Computer Science & Information Technology