I still get 1 using this :/
You enter 0 and 20 as the values for a and b?
Is the return value of expression only depending on the two arguments?
yep!
well, expression returns
return sqrt(a*a +b*b) *sum(20000);
sum(20000) is another user defined functions which then relies on another two user defined functions..all of which work perfectly well
Can you show sum and the two other functions, if you don't mind?
I can't Im sorry. But I evaluated all of the functions as above and have realised sum is the problem - it comes up with "nan"
Just for your own sanity, I'd modify your code to print out the values of a and b, just so you're sure they're correct:
1 2 3 4 5 6 7 8
|
if (cin >> a >> b)
{
cout << "expression(" << a << "," << b << ") = " <<expression(a, b) << endl;
}
else
{
cout << "Invalid input!" << endl;
}
|
Edit: Actually, what I'd really suggest is stepping through your code in a debugger, so that you can see exactly what's going on.
Last edited on