No Blog
We need to say NO

Home Page




How do I write this C++ program with a function that takes as arguments an integer and a double?

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



Tags: , ,

7 Responses to “How do I write this C++ program with a function that takes as arguments an integer and a double?”

  1. AJ Says:

    Try doing your own homework. They give you these problems so you can learn to do it.

  2. Kenneth Says:

    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.

  3. wassabison Says:

    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”.

  4. Mike B Says:

    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

  5. XoaX.net Says:

    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:

  6. jeo Says:

    you cannot return two values

    you are providing partial info

  7. He_Who_Shall_Not_Be_Named Says:

    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

Leave a Reply