S
Steve
Okay, here's the challenge, I know its probably pretty easy, but i'm just
starting to learn and I have the challenge problem that I can't figure out,
any help/guidance would be appreciated!
This program will accept two numbers from the user and display the sum of
the square roots of the numbers. It will do this by calling a function called
"mySquareRoot", which you will write. If the number passed to the function is
negative, the function will return the negative of the square root of the
positive number. The program will stop when the user enters a zero for either
number. The "main" function is already written; you just need to write the
"mySquareRoot" function and make any other changes necessary to get the
program to work properly. You should use
the "sqrt" function in "cmath". To save yourself time, copy
the code below into your project.
code:
// ******************** I M P O R T A N T ! ! ! *************
// Do not change ANYTHING in main!!
// *****************************************************
int main()
{
double x, y;
do
{
cout << "Please enter the first number: ";
cin >> x;
if (x != 0)
{
double answer1 = mySquareRootFunction(x);
cout << "The first square root is " << answer1 << endl;
cout << "Please enter the second number: ";
cin >> y;
if (y != 0)
{
double answer2 = mySquareRootFunction(y);
cout << "The second square root is " << answer2 << endl;
cout << "The sum of " << answer1 << " and " << answer2;
cout << " is " << (answer1+answer2) << endl;
}
}
} while ((x != 0) && (y != 0));
}
Thanks!
starting to learn and I have the challenge problem that I can't figure out,
any help/guidance would be appreciated!
This program will accept two numbers from the user and display the sum of
the square roots of the numbers. It will do this by calling a function called
"mySquareRoot", which you will write. If the number passed to the function is
negative, the function will return the negative of the square root of the
positive number. The program will stop when the user enters a zero for either
number. The "main" function is already written; you just need to write the
"mySquareRoot" function and make any other changes necessary to get the
program to work properly. You should use
the "sqrt" function in "cmath". To save yourself time, copy
the code below into your project.
code:
// ******************** I M P O R T A N T ! ! ! *************
// Do not change ANYTHING in main!!
// *****************************************************
int main()
{
double x, y;
do
{
cout << "Please enter the first number: ";
cin >> x;
if (x != 0)
{
double answer1 = mySquareRootFunction(x);
cout << "The first square root is " << answer1 << endl;
cout << "Please enter the second number: ";
cin >> y;
if (y != 0)
{
double answer2 = mySquareRootFunction(y);
cout << "The second square root is " << answer2 << endl;
cout << "The sum of " << answer1 << " and " << answer2;
cout << " is " << (answer1+answer2) << endl;
}
}
} while ((x != 0) && (y != 0));
}
Thanks!