Hi I am having trouble using the power function for integers, I need the result to be an integer number. I'm trying to get the user to type in both the values of the base and the exponent but I keep getting an error that says:
ambiguous call to overloaded function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <cmath>
usingnamespace std;
int main(){
int base=0, exponent=0, power =0;
cout<<"Enter base\n";
cin<<base;
cout<<"Enter exponent\n"
cin<<exponent;
power= (int) pow((int) base, (int)exponent);
cout<<power;
return 0;
}
Sorry I wasn't trying to come off as upset. But it still doesn't work, I use Microsoft Visual Studios, it keeps giving me an error that my 'pow' is ambiguous to overloaded function
But what if I want the result to come out as an integer? Is there any way I could go about doing that? Or is it not possible for me to use the power function. And I did try that but it gives me the same error
You also need cin.ignore().get(); before the return to keep the console screen from disappearing,
ie as a system replacement. Then you can view the result.
My prof told me to use a breakpoint. But I am new at c++, so I was wondering does it matter what program I use to run it into? What are you guys using because I am using Microsoft Visual Studios and it still gives me that error
Have you compiled many other programs in MVS? If not, or other problems of this nature have occurred, then reinstalling wouldn't hurt. Otherwise, I am at a loss. I am running it fine in Code::Blocks.
If you were referring to how to keep the console open, yes, you can put that code into any program to keep it from closing. That way, if you want to simply double click the executable, you can without it closing early.
The problem for me is I need to keep those identifiers as ints, I can't change them into doubles because I am making a program that's a lot more complex than that and it requires them to be ints. Is there any way I could use the power function and keep those as ints?
I 'm not sure that 'pow' function will accept just int (as indicated by the initial error).
Anyway, as I posted before a double / float is the same as an integer with the difference being that they accept decimal values where as int does not. IE: