monopoly game

Jul 16, 2013 at 6:27pm
well i can't explain a code now it's not complete but what is the wrong with struct player lin32
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  #include<iostream>
#include<ctime>
#include<string>
using namespace std;
char c; //for buy or not places
struct places {
	int price;
	int rent;
};
void egyptf();
void syriaf();
void paletinef();
void iraqf();
void libyaf();
void sudanf();
void ksaf();
void qatarf();
void moracof();
void lebanonf();
void alegireaf();
void emaratf();
void kuwitf();
void bahrenf();
	int dice(int roll)
	{
	srand((unsigned int)time(NULL));
	roll=rand() % 6+1;
	cout<<roll<<endl;
	cin.get();
		return(roll);
	}
	struct player {
	 int salary==300;
		int fortune;
	}playerm,computer;
	void player1d()
	{
		playerm.fortune=1200;
	}
int main()
{
	int r=0;
	int *p;
		r=dice(r);
	cout<<"this is r:"<<r;
	cout<<endl;
	p=&r;
	switch (*p)
	{
	case 1:
		 egyptf();
		break;
	case 2:
		syriaf();
		break;
	case 3:
		paletinef();
		break;
	case 4:
		iraqf();
		break;
	case 5:
		libyaf();
		break;
	case 6:
		sudanf();
		break;
	default :
		ksaf();
		break;
	}
	return 0;
}
void egyptf()
{
	bool sell=false;
	places egypt;
	egypt.price=500;
	egypt.rent=50;
	cout<<egypt.price<<egypt.rent<<endl;
	cout<<"Do u want to buy it?(y/n)";
	cin>>c;
	if(c='y')
	{
		playerm.fortune=playerm.fortune-500;
		cout<<"now your fortune is:"<<playerm.fortune<<endl;
	}
	else
		main();
}
void syriaf()
{
	bool sell=false;
	places syria;
	syria.price=300;
	syria.rent=20;
	cout<<"This is free syria:"<<syria.price<<", "<<syria.rent<<endl;
}
void paletinef()
{
	bool sell=false;
	places palestine;
	palestine.price=250;
	palestine.rent=25;
	cout<<"This is free syria:"<<palestine.price<<", "<<palestine.rent<<endl;
}
void iraqf()
{
	bool sell=false;
places iraq;
iraq.price=150;
iraq.rent=35;
cout<<"this is Iraq:"<<iraq.price<<", "<<iraq.rent<<endl;
}
void libyaf()
{
	bool sell=false;
	places libya;
libya.price=150;
libya.rent=35;
cout<<"this is libya:"<<libya.price<<", "<<libya.rent<<endl;
}
void sudanf()
{
	bool sell=false;
	places sudan;
sudan.price=150;
sudan.rent=35;
cout<<"this is sudan:"<<sudan.price<<", "<<sudan.rent<<endl;
}
void ksaf()
{
	bool sell=false;
	places ksa;
ksa.price=150;
ksa.rent=35;
cout<<"this is ksa:"<<ksa.price<<", "<<ksa.rent<<endl;
}
void qatarf()
{
	bool sell=false;
	places qatar;
qatar.price=150;
qatar.rent=35;
cout<<"this is qatar:"<<qatar.price<<", "<<qatar.rent<<endl;
}
void moracof()
{
	bool sell=false;
	places moraco;
moraco.price=150;
moraco.rent=35;
cout<<"this is moraco:"<<moraco.price<<", "<<moraco.rent<<endl;
}
void lebanonf()
{
	bool sell=false;
	places lebanon;
lebanon.price=150;
lebanon.rent=35;
cout<<"this is lebanon:"<<lebanon.price<<", "<<lebanon.rent<<endl;
}
void alegireaf()
{
	bool sell=false;
	places alegirea;
alegirea.price=150;
alegirea.rent=35;
cout<<"this is alegirea:"<<alegirea.price<<", "<<alegirea.rent<<endl;
}
void emaratf()
{
	bool sell=false;
	places emarat;
emarat.price=150;
emarat.rent=35;
cout<<"this is alegireaf:"<<emarat.price<<", "<<emarat.rent<<endl;
}
void kuwitf()
{
	bool sell=false;
	places kuwit;
kuwit.price=150;
kuwit.rent=35;
cout<<"this is alegireaf:"<<kuwit.price<<", "<<kuwit.rent<<endl;
}
void bahrenf()
{
	bool sell=false;
	places bahren;
bahren.price=150;
bahren.rent=35;
cout<<"this is bahren:"<<bahren.price<<", "<<bahren.rent<<endl;
}
Jul 16, 2013 at 6:42pm
closed account (Dy7SLyTq)
line 33
Jul 16, 2013 at 6:58pm
Or more specifically you're using an "is equals" operator instead of an assignment operator.
Jul 16, 2013 at 8:24pm
still have
Error 1 error C2143: syntax error : missing ';' before '=='
and
Error 2 error C2238: unexpected token(s) preceding ';'
and
3 IntelliSense: data member initializer is not allowed
i have checked the code i'm sure that i didn't forget any ";"
Jul 16, 2013 at 8:29pm
No, no. You're just using == instead of =.
Jul 16, 2013 at 8:40pm
closed account (1v5E3TCk)
As I said before this code would be better:
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
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include <ctime>
#include <string>

using namespace std;

void declare();
int dice();
void func_pos();

struct places {
    string name;
	int price;
	int rent;
	int number;
	int owner;
};

struct player {
    int money;
    int position;
};

player me;
places turkiye[ 11 ];

void declare()
{
       me.money = 350;
       me.position = 0;

       turkiye[ 0 ].name = "start";
       turkiye[ 0 ].number = 0;
       turkiye[ 0 ].owner = 0;
       turkiye[ 0 ].price = 0;
       turkiye[ 0 ].rent = 0;

       turkiye[ 1 ].name = "Istanbul";
       turkiye[ 1 ].number = 1;
       turkiye[ 1 ].owner = 0;
       turkiye[ 1 ].price = 200;
       turkiye[ 1 ].rent = 50;

       turkiye[ 2 ].name = "Ankara";
       turkiye[ 2 ].number = 2;
       turkiye[ 2 ].owner = 0;
       turkiye[ 2 ].price = 160;
       turkiye[ 2 ].rent = 40;

       turkiye[ 3 ].name = "Izmır";
       turkiye[ 3 ].number = 3;
       turkiye[ 3 ].owner = 0;
       turkiye[ 3 ].price = 150;
       turkiye[ 3 ].rent = 35;

       turkiye[ 4 ].name = "Corum";
       turkiye[ 4 ].number = 4;
       turkiye[ 4 ].owner = 0;
       turkiye[ 4 ].price = 80;
       turkiye[ 4 ].rent = 15;

       turkiye[ 5 ].name = "Antalya";
       turkiye[ 5 ].number = 5;
       turkiye[ 5 ].owner = 0;
       turkiye[ 5 ].price = 160;
       turkiye[ 5 ].rent = 40;

       turkiye[ 6 ].name = "Bolu";
       turkiye[ 6 ].number = 6;
       turkiye[ 6 ].owner = 0;
       turkiye[ 6 ].price = 120;
       turkiye[ 6 ].rent = 30;

       turkiye[ 7 ].name = "Trabzon";
       turkiye[ 7 ].number = 7;
       turkiye[ 7 ].owner = 0;
       turkiye[ 7 ].price = 90;
       turkiye[ 7 ].rent = 20;

       turkiye[ 8 ].name = "Mugla";
       turkiye[ 8 ].number = 8;
       turkiye[ 8 ].owner = 0;
       turkiye[ 8 ].price = 110;
       turkiye[ 8 ].rent = 35;

       turkiye[ 9 ].name = "Adana";
       turkiye[ 9 ].number = 9;
       turkiye[ 9 ].owner = 0;
       turkiye[ 9 ].price = 80;
       turkiye[ 9 ].rent = 15;

       turkiye[ 10 ].name = "Hakkari";
       turkiye[ 10 ].number = 10;
       turkiye[ 10 ].owner = 0;
       turkiye[ 10 ].price = 60;
       turkiye[ 10 ].rent = 10;
}

int dice( )
{
    int roll;

	roll= (rand()%6) + 1;

	cout<<"u will move "<< roll <<" block(s)"<<endl;

	cin.get();
    return roll;
}

void func_pos()
{
    int choose;
    int x = me.position;

    cout<< "You are at "<< turkiye[ x ].name <<'\n';

    if( me.position != 0 & turkiye[ x ].owner == 0)
    {
        cout<< "1.Buy\n";
        cout<< "2.Dont buy\n";
        cin>> choose;

        switch(choose)
        {
            case 1:
                me.money -= turkiye[ x ].price;
                turkiye[ x ].owner = 1;
            case 2:
                cout<< "Okey, let you go";
        }
    }

    else if( me.position != 0 & turkiye[ x ].owner != 0)
    {
        cout<< "You paid " << turkiye[ x ].rent << " as rent\n";
    }


}

int main()
{
    declare();

    srand(time(NULL));

    do
    {
        int g;
        g = dice();

        me.position += g;

        if( me.position >= 10)
        {
            me.position -= 10;
            me.money += 300;
        }

        func_pos();

    } while( me.money != 500);


	return 0;
}
Jul 17, 2013 at 7:03am
but functions is faster than arrays
i mean make the code faster to complire xd
Jul 17, 2013 at 7:59am
@DTS
line 33


i agree
Topic archived. No new replies allowed.