Error Messages When Compiling Card Game (Red Dog)

I've been trying to compile my code for the card Game "RED DOG" and I've been getting the same two error messages. 1. expected ';' before '{' token for line 28 and 2. expected '}' at end of input. I especially don't understand the second error message because I have an equal number of open and closed brackets. If someone could help me resolve these two issues, that would be awesome!

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
#include <iostream>
#include <cmath>
#include <time.h>
#include <stdlib.h>

using namespace std;


void printTitle ()
{
cout << "********** WELCOME TO RED DOG **********"<<endl;
}

int bank = 5000;
void displayCard (int card1, int card2, int card3);
char valid1 = 'n';
char valid2 = 'o';
int bet = 0;



int main () 

   
{

printTitle ()
{

	srand(time(0));
	card1 = rand () %13 +1;
	card2 = rand () %13 +1;
	card3 = rand () %13 +1;
	
	
	
	while (valid1 == 'n');
{      
         if (card1 == card2 || card1 == card3)
		 {
		         srand(time(0));
				 break;
			}
		else if (card2 == card1 || card2 == card3)
		{	
				srand (time (0));
				break;
			}
			else 
				break;
}
cout << "Card 1:"<<card1<<endl;
cout << "Card 2:"<<card2<<endl;
		if(card1==11)
		{
			cout<<"Jack"<<"\t"<<card2;	
		}
		else if(card2==11)
		{
			cout<<"Jack"<<"\t"<<card1;
		}
		else if(card1==12)
		{
			cout<<"Queen"<<"\t"<<card2;
		}
		else if(card2==12)
		{
			cout<<"Queen"<<"\t"<<card1;
		}
		else if(card1==13)
		{
			cout<<"King"<<"\t"<<card2;
		}
		else if(card2==13)
		{
			cout<<"King"<<"\t"<<card1;
		}
		else
		{
			cout<<card1<<"\t"<<card2<<endl;
		}
		while(valid2 =='o')
		{
			cout<<"Enter your bet."<<endl;	
			cin>>bet;
			if(bet>5000)
			{
				cout<<"Invalid bet. Please reenter."<<endl<<endl;	
				continue;
			}
			else if(bet<0)
			{
				cout<<"Invalid bet. Please reenter."<<endl<<endl;
				continue;
			}
			else
			{
				break;
			}
		}
		if(card3>card1 && card3<card2)
		{
			cout<<"Card 3:"<<card3<<endl;	
		}
		else if(card3>card2 && card3<card1)
		{
			cout<<"Card 3:"<<card3<<endl;
		}
		else
		{
			money-=bet;
			cout<<"You lost."<<endl;
			cout<<"You now have "<<money<<endl;	
		}
	cout << "Would you like to bet again? Press 'Y' for yes and 'N' for no. "<<endl;
				cin >>ans;
				if (ans == 'Y' || 'y')
					cout << "Game over, have a great day!"<<;
				
				if (ans == 'N' || 'n')
				continue;
}
	
	if (bank == 0)
	{
		cout<<"Game Over"<<endl;	
		return 0;
	}


}
On line 27 you need a semicolon after the function call. But now I realize that you're trying to define the function inside of main(). You can't define a function inside of another one.
The whole program is ridden with errors, mainly simple syntactical ones.
What is concerning me is that you're trying to compile a game which you evidently didn't write but you can't read the compiler errors correctly.
I would suggest reading a book on basic C++ or read articles on it before trying something as ambitious as this.

Good luck!
Last edited on
Line 27: Needs a ; as pointed out previously.

Line 28: Extraneous { Remove it.

Lines 31-33: card1, card2, card3 do not exist.

Line 41, 46: Do not call srand() multiple times. srand() sets the RNG to a particular starting point. Calling srand() repeatedly can cause the RNG to return the same random numbers. srand() should be called ONCE at the beginning of main().
http://www.cplusplus.com/reference/cstdlib/srand/
This makes the whole loop from 37-51 pointless.

Line 111: money is undefined.

Line 116: ans is undefined.

Lines 117,120: C++ does not support implied left hand side in conditionals. You must fully specify the conditions.
Example:
if (ans == 'Y' || 'y') evaluates as if ((ans == 'Y') || ('y'))

('y') always evaluates to 1 (true), therefore the if statement is always true.

Line 118: Extraneous << or you're missing endl

Line 121: continue is not part of a loop.

Line 122: extraneous } Remove it.

Topic archived. No new replies allowed.