Void Function

 ``1234567891011121314151617181920212223242526272829303132333435363738`` ``````include #include using namespace std; void fun(float); int main () { float a,b,x; int ok; do { cout << " Enter 2 numbers -> " << endl; cin >> a; cout << endl; cin >> b; cout << endl; x=((a*a)+(b*b)); fun(x); cout << " End (0) Continue (1) ?" << endl; cin >> ok; cout << endl; }while(ok==1); return 0; } void fun(float i) { float x; cout << " Third size for the side = "; cout << sqrt(x); }``````

Basically what i'm trying to do is to create a primitive Pythagorean theorem.
You enter 2 numbers. a, b. then a^2 + b^2, and then Square root from both of those numbers.
I've no idea what i'm doing wrong, it always gives me same number 1,29 regardless of what numbers i enter.
You calculate the square root of uninitialized local variable. So the function behavior is undefined

 ``12345678`` `````` void fun(float i) { float x; // what is value of x?!!! cout << " Third size for the side = "; cout << sqrt(x); // Should you use here i instead of x? }``````
Last edited on
Thanks a lot, trying to learn on my own and it's rather confusing.
Again, thanks.
Topic archived. No new replies allowed.