How do I write this C++ program with a function that takes as arguments an integer and a double?
August 8th, 2009 Posted by: admin
These are the specific directions: Write a function called Square2 that will take as arguments an integer and a double. With the use of references your function should return the square of both values. Test the function in main by asking the user to input an integer and a double. When the Square2 function returns print out the square of both values.
I just have no idea what to do. I am new to C++ programming.
By: Liz
I just have no idea what to do. I am new to C++ programming.
By: Liz
Tags: C Program, C Programming, Directions

August 9th, 2009 at 05:47
Try doing your own homework. They give you these problems so you can learn to do it.
August 10th, 2009 at 13:15
err, a function cannot have two return values. you may have put it wrong there buddy.
also, try to google and research about this. only you can help yourself with this.
August 14th, 2009 at 00:39
the function will look like this
void Square2(int val1, double val2, int & result1, double& result2)
{
result1 = val1*val1;
result2 = val2*val2;
return;
}
The other poster who said you could not have two returns did not read the question or does not know C++.
To other posters.
It is clear from the description of the problem that they were using the loose linguistic meaning of return. In the question it states “With the use of references your function should return the square of both values.” This is exactly what the code snippet showed.
Also I never said that you could have two returns, I said that the person did not read the question or does not know C++. I stand by that statement.
One more thing, from your own sources… “Passing by reference is also an effective way to allow a function to return more than one value. For example, here is a function that returns the previous and next numbers of the first parameter passed.” Notice the language they use? They use the phrase “return more than one value”.
August 15th, 2009 at 02:37
You should do your own homework.
And you CANNOT have two returns. What wassibison did does not mean he has two returns.
I recommend this website’s tutorial
August 18th, 2009 at 11:08
That is not too difficult. This video should explain it for you:
You need to return the values through reference arguments.
If you still have questions after you watch that, let me know:
August 20th, 2009 at 13:28
you cannot return two values
you are providing partial info
August 23rd, 2009 at 08:55
Is this what you want?:
#include
#include
using namespace std;
double Square2(int var1, double var2);
int main()
{
int var3;
double var4;
cout > var3;
cout > var4;
double result = Square2(var3, var4);
double& square = result;
cout