include <iostream>
#include <cmath>
usingnamespace 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
1 2 3 4 5 6 7 8
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?
}