Functinos C++

While calling for function "strategy" on the main function it will execute how it should, but once I ask to return the value it will just return

Enter player1's roll until strategy: 10 Enter player2's roll until strategy: 5

0 0 press any key to contiue...

does anyone know why this is happening or what is causing it, was my error in the strategy function? or upon calling it? im kinda new to Functions im still learning :)

thnks for the help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<cstdlib>
#include<string>
#include<time.h>
using namespace std;

//Functions
// player strategy
int strategy(int user1Strat, int user2Strat);
// player total score per round
int currentScore();
// Display game result
void printResults();

int main()
{
	int total_player1 = 0; // player 1 current score
	int total_player2 = 0; // player 2 current score
	int player1_strat= 0;  //player 1 strategy for each turn
	int player2_strat = 0; // player 2 strategy for each turn

	// seed the random number generator.
    srand(static_cast<int> (time(NULL)));

	// get strategy for each player using functions <strategy>

	strategy(player1_strat, player2_strat);

	cout << player1_strat << endl << player2_strat << endl;

	system("pause");
	return 0;
}

int strategy(int user1Strat, int user2Strat)
{
	int x,
		y;

	cout << "Enter player1's roll until strategy: ";
	cin >> user1Strat;
	cout << "Enter player2's roll until strategy: ";
	cin >> user2Strat;
	x = user1Strat;
	y = user2Strat;

	return x, y;
}


i want user1Strat to pass value to player1_strat and user2Strat to pass value to player2_strat.

sorry for bad code :<
Last edited on
You can't return two variables. You'll need to pass player1_strat and player2_strat by reference if you want them to change in main.

Read about reference parameters here: http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/
Topic archived. No new replies allowed.