Undefined Error


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
  #include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>


void Card1();
void Card2();
void twentyOne(int totalchips);
using namespace std;

int main()
{

cout << "Welcome to the Finger Bang Casino.\n";
cout << "You have recieved 100 chips.\n";

twentyOne(100);

}

void twentyOne(int totalchips)
{
srand(time(0));
int rNumber[2]= {1+(rand()%13), 1+(rand()%13)};
int bet;

cout << "You have recieved a(n) ";

Card1();
Card2();

}


void Card1(int rNumber[2])
{

    if (rNumber[0] < 10)
    {
        cout << rNumber[0] << " ";
    }
    else if(rNumber[0] > 12)
    {
    cout << "Ace ";
    }
    else if(rNumber[0] > 11 )
    {
    cout << "King ";
    }
    else if(rNumber[0] > 10)
    {
        cout << "Queen ";
    }
    else if(rNumber[0] > 9)
    {
        cout <<"Jack ";
    }
}

void Card2(int rNumber[2])
{


    if (rNumber[1] < 10)
    {
        cout << rNumber[1];
    }
    else if(rNumber[1] > 12)
    {
    cout << "Ace ";
    }
    else if(rNumber[1] > 11 )
    {
    cout << "King ";
    }
    else if(rNumber[1] > 10)
    {
        cout << "Queen ";
    }
    else if(rNumber[1] > 9)
    {
        cout <<"Jack ";
    }
}


The error is for Card1 and Card2. I googled it and everything, but I guess I am not understanding it clearly. What I am trying to do create a rNumber Array then be-able to pass them into Card1 and Card2, but I literally have tried a different ways of coding it, so I am stuck atm. Any help would be really appreciated.
Last edited on
What is your compiler saying is undefined, your problem is too vague to answer without more details

Arrays should be passed by reference:
1
2
3
4
5

void Card2 (int &rNumber)
{
     //function body
}
undefined reference to Card1() and Card2(). That is the error. I changed it to void Card2 (int rNumber), but how will the code know between rNumber[0] and rNumber[1]?
you tell it which one to use, all you are doing is passing the memory address to the function.

If you pass an array like this:
1
2
3
4
5
6

void function (int array[x][y])
{

}


What you are actually doing is making another array, containing all of the data of the original array. While this doesn't pose huge consequences in small or trivial programs, it is not good for memory consumption in larger ones, and overall considered to be bad practice if it can be avoided by simply passing the memory address.
Topic archived. No new replies allowed.