Hey guys, I'm new here, obviously so if I do anything wrong let me know (gently). This program out puts x = 4 and y = 64 and I'm not sure why?


[#include <cmath>
#include <iostream>

using namespace std;

double Square(double);
double Cube(double);

int main(void)

{ double x = 2.0, y = 3.0;
x = Square(x);
y = Cube(x);
cout << "x = " << x << endl;
cout << "y = " << y << endl;
system("Pause");

return 0;
}

double Square(double y)
{
double x = pow(y,2);
return x;
}

double Cube(double x)
{
double y = pow(x,3);
return y;
}
]
any help would be awesome. thanks

Hey guys, I'm new here, obviously so if I do anything wrong let me know (gently). This program out puts x = 4 and y = 64 and I'm not sure why?


[#include <cmath>
#include <iostream>

using namespace std;

double Square(double);
double Cube(double);

int main(void)

{ double x = 2.0, y = 3.0;
x = Square(x);
y = Cube(x);
cout << "x = " << x << endl;
cout << "y = " << y << endl;
system("Pause");

return 0;
}

double Square(double y)
{
double x = pow(y,2);
return x;
}

double Cube(double x)
{
double y = pow(x,3);
return y;
}
]
any help would be awesome. thanks

Hey man, don't forget to use code tags when you post code here.

it should be y = Cube(y).

you're squaring x, then cubing it again in your code.

Well the first function takes a value and squares it with pow() and then passing the answer 4 to the second function which cubes it 4^3 = 64.

Thanks for the great replies. I just want to make sure I understand when you say code tags, is that just me telling everyone that it's C++ before the actual code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.