**C++ PROGRAMMING PROBLEM **

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!
 
D

Dirk Goldgar

Steve said:
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.


Sorry, your homework is for you to do.

In the context of doing your homework, you might do a little more and learn
that this newsgroup is for programming Microsoft Access, the database
program, and C++ is not relevant to it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top