Risk Game (function calling)

Hello I am trying to call the function match() to main and i keep getting an error about int not being able to be used. Even though the compiler(visual studio) recommends int to be used. If you see any other problems I'm up for tips! Thank You!!!

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int roll();
void sortRolls(int& a, int& b);
void sortRolls(int&a, int&b, int&c);
bool attackerLoses(int attackRoll, int defendRoll);
void riskRoll(int& strengthOfA, int& strengthOfD);
void match(int strenthOfA, int strengthOfD);
void extendRolls(int&attackStreng, int&defendStreng);

int main()
{
	match();

	return 0;
}
	

	int roll()
	{	
		return (rand()%6)+1;
	}

	void sortRolls(int&a, int&b)
	{
		a = roll();
		b = roll();
		if(b >= a)
			swap(a,b);
		return;
	}

	void sortRolls(int&a, int&b, int&c)
	{
		a = roll();
		b = roll();
		c = roll();
		if(c >= b)
			swap(c,b);
		if(c >= a)
			swap(c,a);
		if(b >= a)
			swap(b,a);
			return;
	}

	bool attackerLoses(int attackRoll, int defendRoll)
	{
		if(attackRoll > defendRoll)
			return false;
		else
			return true;
	}

	void riskRoll(int& strengthOfA, int& strengthOfD)
	{
		int  rollA, rollB, firstADie, secondADie, thirdADie,firstDDie, secondDDie;
		if(strengthOfA > 3)
			{
				rollA = 3;
				sortRolls(firstADie, secondADie, thirdADie);
			}
		if(strengthOfA = 2)
			{
				rollA = 2;
				sortRolls(firstADie, secondADie);
			}
		if(strengthOfD > 2)
			{
			    rollB = 2;
				sortRolls(firstDDie, secondDDie);
			}
		if(strengthOfD = 1)
			{
				rollB = 1;
				firstDDie = roll();
			}
		cout << "You have made a roll!\n";
	}

	void match(int strenthOfA, int strengthOfD)
	{
		void extendRolls();
		cout << "You have started a new match!\n";
	}

	void extendRolls(int& strengthOfA, int& strengthOfD)
	{
		cout << "Enter your attacking strength.\n";
		cin >> strengthOfA;
		cout << "Enter your defending strength.\n";
		cin >> strengthOfD;
		riskRoll(strengthOfA, strengthOfD);
		if (strengthOfA > strengthOfD)
			cout << "Attacker Wins!\n";
		else
			cout << "Defender Wins!\n";
	}
Your definition and declarations of the match function are void match( int strengthOfA , int strengthOfD );

Yet you are calling match( void ) instead of match( int , int );
okay i corrected it...but now all i get is press any key to continue. What do i need to do to get match() to run in the main() and then read extendRolls()?

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int roll();
void sortRolls(int& a, int& b);
void sortRolls(int&a, int&b, int&c);
bool attackerLoses(int attackRoll, int defendRoll);
void riskRoll(int& strengthOfA, int& strengthOfD);
void match(int strenthOfA, int strengthOfD);
void extendRolls(int&attackStreng, int&defendStreng);

int main()
{
void match(int strengthOfA, int strengthOfD);

return 0;
}


int roll()
{
return (rand()%6)+1;
}

void sortRolls(int&a, int&b)
{
a = roll();
b = roll();
if(b >= a)
swap(a,b);
return;
}

void sortRolls(int&a, int&b, int&c)
{
a = roll();
b = roll();
c = roll();
if(c >= b)
swap(c,b);
if(c >= a)
swap(c,a);
if(b >= a)
swap(b,a);
return;
}

bool attackerLoses(int attackRoll, int defendRoll)
{
if(attackRoll > defendRoll)
return false;
else
return true;
}

void riskRoll(int& strengthOfA, int& strengthOfD)
{
int rollA, rollB, firstADie, secondADie, thirdADie,firstDDie, secondDDie;
if(strengthOfA > 3)
{
rollA = 3;
sortRolls(firstADie, secondADie, thirdADie);
}
if(strengthOfA = 2)
{
rollA = 2;
sortRolls(firstADie, secondADie);
}
if(strengthOfD > 2)
{
rollB = 2;
sortRolls(firstDDie, secondDDie);
}
if(strengthOfD = 1)
{
rollB = 1;
firstDDie = roll();
}
cout << "You have made a roll!\n";
}

void match(int strenthOfA, int strengthOfD)
{
void extendRolls();
cout << "You have started a new match!\n";
return;
}

void extendRolls(int& strengthOfA, int& strengthOfD)
{
cout << "Enter your attacking strength.\n";
cin >> strengthOfA;
cout << "Enter your defending strength.\n";
cin >> strengthOfD;
riskRoll(strengthOfA, strengthOfD);
if (strengthOfA > strengthOfD)
cout << "Attacker Wins!\n";
else
cout << "Defender Wins!\n";
}
1
2
3
4
5
6
int main()
{
    void match(int strengthOfA, int strengthOfD);

    return 0;
}

Here, line 2 is a declaration. It doesn't call match. In fact, all main does is return.


1
2
3
4
int main()
{
    match(1,2) ;
}

would actually call match.
Last edited on
okay that works but now my extendRolls towards the bottom will not run. I tried to correct it like you did but I keep getting too few arguments.
I think you need to have a look at how functions work check out these links:
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/
http://www.learncpp.com/ --chapter 7
Thanks, normally i have time to test and check but i procrastinated and I'm just trying to get it done so i can turn it in.
Topic archived. No new replies allowed.