Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5248
Number of posts: 16673

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
function call help Posted by crazyjdog on 6 Dec 2009 at 11:24 PM
The question asks for two numbers to be entered and the first number is to be raised to the power of the second number entered. The problem I am having is when I go to compile my program I get a logic error, and when I include the actual function in my function call the program will not compile and give me the error: ambiguous call to overloaded function. Any help that can be given is and will be greatly appreciated. Here is my code with the pow() function included in the function call:
#include <iostream>
#include <cmath>
using namespace std;

void powfun(long x, long y); 

int main()
{
	long firstnum, secnum;
	cout << "\nPlease enter a positive integer: ";
	cin >> firstnum;
	cout << "\nGreat! Now please enter a second positive integer: ";
	cin >> secnum;
	powfun(firstnum, secnum);
	system ("pause");
	return 0;
}
void powfun(long x, long y)
{
	long result;
	result = pow(x, y);
	cout << "\nThe answer is: " << result << endl;
	return;
}

Report
Re: function call help Posted by AsmGuru62 on 7 Dec 2009 at 5:13 AM
Please post the error message itself.
Report
Re: function call help Posted by crazyjdog on 7 Dec 2009 at 11:21 AM
error C2268:'pow': ambiguous call to overloaded function
that's what comes up with the pow() in the function call with out the pow() the program will run but it will stop once I enter the two numbers and give me this message: Run-Time Check Failure #3 - The variable 'result' is being used without being initialized. and the result I get from what is supposed to be 2 to the 2nd power is -858993460 I hope this helps get you guys the info needed to help me figure this out.
Report
Re: function call help Posted by CERN on 7 Dec 2009 at 8:45 PM
The problem was that the pow function overloaded. try changing the long variables (long firstnum, secnum) to double firstnum, secnum. that should do the trick, laptop running out of battery, just change that and it should work. good luck
Report
Re: function call help Posted by crazyjdog on 8 Dec 2009 at 3:17 AM
I figured it out turns out where I had x and y in the function call I needed to have the variables that I declared in the main(). Anyways, thanks for all the help that was given it was greatly appreciated.
Report
Re: function call help Posted by manjunathsoft8 on 28 Dec 2009 at 10:57 PM
hi
this is manjunath!!!
i tried ur code on my turbo compiler.i truncated that system("pause")part and was able to get result!!
i don find prob in ur code.its correct!!
Report
Re: function call help Posted by manjunathsoft8 on 28 Dec 2009 at 10:59 PM
hi
this is manjunath!!!
i tried ur code on my turbo compiler.i truncated that system("pause")part and was able to get result!!
i don find prob in ur code.its correct!!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.