Answer to Question #202421 in C++ for Jordaine Myrie

Question #202421

Write a C++ program that accepts a base value, x, and a power value, k. The program must use an appropriate in-built function (from the CMATH library) to obtain the result of x k . The solution must repeat the instructions, for obtaining x and k to compute and output x k , for TEN (10) times.


1
Expert's answer
2021-06-04T06:08:03-0400
#include <iostream>
#include <cmath>

int main()
{
    for(int i = 0; i < 10; ++i)
    {
        std::cout << "Please enter a base and a power values: ";
        double x, k;
        std::cin >> x >> k;
        
        if(!std::cin)
        {
            std::cout << "Bad input!\n";
            return 1;
        }

        std::cout << x << " ^ " << k << " = " << std::pow(x, k) << "\n";
    }
    
    return 0;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog