Please help with blackjack program

These are the two errors I am receiving:

Line 21: error: expected constructor, destructor, or type conversion before '(' token
compilation terminated due to -Wfatal-errors.

Any information would be appreciated.

I am a complete beginner

Thanks

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
#include <cstdlib> 
#include <ctime>
#include <cmath>

using namespace std; 


int bank = 100;
int bet;
int card1;
int card2;
int card3;
int dealer;
int hand;

char hit;
char play;
char quit;

srand((unsigned)time(NULL));

int main()

{
        cout << "Welcome to Blackjack \n";
        cout << "Press y to play or n to quit \n";
        cin >> play;

    }


int begin()

{

if (play == 'y'){
   
        cout << "You will start with $100 in the bank \n";
}

if (play == 'n'){

        return 0;
}
}

int placebet()
{

  while (play == 'y')

 {
      
        cout << "You currently have  $ "<< bank <<" \n";   
        cout << "Enter your bet \n";
        cin >> bet;

            if (bank == 0){
  
                cout << "You are out of money game over \n";
   
                return main();}
        

            if (bet > bank){
    
                cout << "You do not have enough money \n";
                return placebet();}
                
                cout << "Your bet is  $ "<< bet <<" \n";
                
                bank = bank - bet

                  cout<< "You have  $ "<< bank <<" left in your bank \n";
            
        }
	}
  	}
        char deal()

	{

           card1 = rand()%13+1;
           card2 = rand()%13+1;  
         
              cout << "Your first two cards are "<< card1 <<"   and   "<< card2 <<" \n";

              hand = card1 + card2;

                   if (hand > 21){
                         cout << "BUST \n";
                         return placebet();
           }

                   else
                      cout << "Your total is "<< hand <<", enter y to hit or n to stay \n";
                      cin >> hit;

                        while (hit == 'y'){

                          card3 = rand()%13+1;
                          cout << "Your third card is "<< card3 <<" \n";
                          
                             hand = card3 + hand;

                             if (hand > 21){

                                  cout << "BUST \n";
                                  return placebet()

                                else
                                  
                                  cout << "Your total is "<< hand <<", enter y to hit or n to stay \n";
                                  cin >> hit;
                       }

                           dealer = 15+rand()%6;
                           cout << "The dealer has a total of "<< dealer <<" \n";

			{

		char decision()

		{
		    if (dealer > hand){

 			 cout << "You have lost this hand \m";
			 cout << "You have a total of  $ "<< bank <<" in the bank \n";
			}

		    if (dealer == hand){
			 
			 cout << "You have lost this hand \n";
			 cout << "You have a total of $  "<< bank <<" in the bank \n";
			}       

                    if (hand > dealer){

                         cout << "You have won this hand \n";
                         bank = bank + 1.5 * bet;
                         cout << "You have have a total of  $ "<< bank <<" in the bank \n";


			}

				cout << "Enter y to play another hand, or n to quit \n";
                                cin >> quit;

				if (quit == 'n'){

				    return 0;}
		
			}




Hi!

You probably meant to call srand() inside main(), near the top. Outside of a function, something like a function call has a different meaning. ;)

-Albatross
Topic archived. No new replies allowed.