Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my pow function returning 0 when it's being called as a variable?

I’m new to coding and have been learning on youtube and one of the functions im learning is the pow function. When i call the function in a cout directly, it outputs the correct value, but when i use a variable to call it, it outputs 0 as the value. Am i missing a step in the declaration of the function?

#include <iostream>
#include <cmath>

using std::cout;
using std::endl;
using std::cin;

int main()
{
      int base, exponent;
      double power = pow(base, exponent);


      cout << "What base do you have? " << endl;
      cin >> base;
      cout << "What exponent do you have? " << endl;
      cin >> exponent;
      cout << power << endl;

   return 0;

 }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Call double power = pow(base, exponent); after base, exponent are assigned values

cin >> exponent;
double power = pow(base, exponent);
cout << power << endl;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading