Triple Variable Count

Hello all. I have a question for homework purposes. Now, I am not asking anyone to do this FOR me. I need help understanding part of it. therefore, I will copy and paste the assignment and divert your attention to the question at hand.


1. Write a complete C++ program with the two alternate functions specified below, of which each simply triples the variable

count defined in main. Then compare and contrast the two approaches. These two functions are

a) Function tripleCallByValue that passes a copy of count call-by-value, triples the copy and returns the new value.

b) Function tripleByReference that passes count with true call-by-reference via a reference parameter and triples

the original copy of count through its alias (i.e., the reference parameter).


My question is about the triple variable count. I understand in loops you have a counter such as:

while (int num=1; num<=10; num++)

now the num++ will only increase it by one. How can I triple this?? Or am I completely missing the objective?

I think you're missing the point of this assignment, which is to understand pass by value vs pass by reference.

Do you understand the difference between these two scenarios? If not, research pass by value and pass by reference.

1
2
3
4
5
6
7
8
9
10
11
int double(int x)
{
    return x*2;
}

int main()
{
    int x = 4;
    cout << double(x);
    return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
int double (int& x)
{
    x*=2;
}

int main()
{
    int x=4;
    double(x);
    cout << x;
    return 0;
}

Last edited on
fail for using double as a function name.
awwwwwwwwwwwwwwwwww god *hangs head in shame* note to self: don't get back from pub at 2am then come onto the forum

EDIT - when reading the question again he didn;t even ask for a function that doubled a variable, he wanted it to triple it. fml
Last edited on
Topic archived. No new replies allowed.