Function Parameters Help...

I want to be able to receive the values of myValueOne and myValueTwo, but the problem is i'm only getting values for the myValueTwo. What am I doing wrong? :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "stdafx.h"
#include <iostream>

typedef short int UINT;

UINT calculate(UINT a, UINT b);

int main()
{
	UINT myValueOne = 0, myValueTwo = 0;
	(myValueOne, myValueTwo) = calculate(myValueOne, myValueTwo);
	std::cout << "First Value: " << myValueOne << std::endl; //this is always displayed as 0. I want it to actually display it's number
	std::cout << "Second Value: " << myValueTwo << std::endl; //this is displayed always
    return 0;
}

UINT calculate(UINT a, UINT b)
{
	std::cout << "Enter in values\nValue 1: ";
	std::cin >> a;
	std::cout << "Value 2: ";
	std::cin >> b;
	return (a, b);
}
C++ only allows a single return value. You cannot return multiple values like you are trying to do.

Instead, you might want to consider passing by reference:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void calculate(UINT& a, UINT& b)
{
	std::cout << "Enter in values\nValue 1: ";
	std::cin >> a;
	std::cout << "Value 2: ";
	std::cin >> b;
}

int main()
{
	UINT myValueOne = 0, myValueTwo = 0;
	calculate(myValueOne, myValueTwo);
	// ...
}
Topic archived. No new replies allowed.