srand 0 doesn't make new numbers

Hi there
I want make new random numbers for each of cb1,cb2,cb3,...
but i dont know they made same
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Group14-6.cpp : main project file.

#include "stdafx.h"
#include "IAUTNB.H"
#include <Windows.h>
#include <time.h>
#include <conio.h>
#include <cstdlib>
#include <mmsystem.h>
#include <stdlib.h>
#pragma comment(lib, "winmm.lib")

void board(int (*array)	[10][10]);
void reset( int *array, int size);
void movement(int [10][10],int&,int&,int&,int&);
int FindMaxArray(int [10][10]);
int FindMinArray(int [10][10]);
void mouse(int);
using namespace std;
/*************************************************************************************************************
                                                main function
**************************************************************************************************************     
                                   این برنامه از فایل های صوتی استفاده می کند     
						  لطفا فایل های در درایوی که ویندوز را نصب شده است ، کپی فرمایید  .wav
						                               مثلا c:
**************************************************************************************************************
*******************************************************************************************************	******/												 
int main(void)  
{
    
	border();
	border2();
	system ("color EC");
	gotoxy(35,4);
	PlaySound( TEXT("\\short.wav"), NULL, SND_FILENAME | SND_ASYNC);
	char gn[25]="Mouse and Cheese \n ";
	show(gn);
	for(int i=0;i<12;i++)
	{
		gotoxy(4,i+6);
		for(int j=0;j<=i;j++)
		  cout<<"  O  ";
		cout<<"\n";
		Sleep(10);
	}
	
	Sleep(1200);
	gotoxy(3,20);
	cout<<"                   Press any key to continue ";
	getch();
    system("cls");
	/*************************************************************************
	*********************************بخش اول برنامه ، یک موش ، یک پنیر *******/
	int cb[10][10];// Chess board صفحه ده در ده
	int x[5], y[5];
	int moves [5];
    int total[5];//Sum of position's number جمع اعدادی که موش از آن ها عبور کرده
	
	
	reset(moves,5);
	reset(x,5);
	reset(y,5);
	reset(total,5);

	board(&cb);

	movement(cb,x[0],y[0],moves[0],total[0]);
	border();
	gotoxy(2,3);
	cout<<"The Little Mouse reached to cheese with "<<moves[0]<<" movements"<<endl;
	gotoxy(2,5);
	cout<<"The mouse has eaten  "<<total[0]<<" rings";
	gotoxy(2,7);
	cout<<"The maximum is "<<FindMaxArray(cb)<<" The minimum is "<<FindMinArray(cb);	
	gotoxy(5,20);
	system("pause");
	system("cls");
	//بخش دوم برنامه

	mouse(1);
	mouse(2);
	mouse(3);
	mouse(4);
	mouse(5);
	reset(moves,5);
	reset(x,5);
	reset(y,5);
	{
		int cb1[10][10];
		int cb2[10][10];
		int cb3[10][10];
		int cb4[10][10];
		int cb5[10][10];
		

	board(&cb1);
	movement(cb1,x[0],y[0],moves[0],total[0]);
	board(&cb2);
	cout<<cb2[0][0]<<endl;
	movement(cb2,x[1],y[1],moves[1],total[1]);
	board(&cb3);
	movement(cb3,x[2],y[2],moves[2],total[2]);
	board(&cb4);
	movement(cb4,x[3],y[3],moves[3],total[3]);
    board(&cb5);
	cout<<cb5[0][0]<<endl;
	movement(cb5,x[4],y[4],moves[4],total[4]);
	}

	int w,speed=moves[0];
	for(int i=0;i<5;i++){
		if(moves[i]>speed){

			speed=moves[i];
			w=i;
		}
	}
	gotoxy(10,10);
	if(w==0)
		cout<<"The fastest mouse was first mouse";
	else if(w==1)
		cout<<"The fastest mouse was second mouse";
	else if(w==2)
		cout<<"The fastest mouse was third mouse";
	else
		cout<<"The fastest mouse was "<<w+1<< "th mouse";

	gotoxy(10,12);
	cout<<"She reached to cheese just with "<<speed<<" moves";
	system("pause");
			


    

    return 0;
}
// تابع حرکات موش
void movement(int a[10][10],int&x,int&y,int&m,int&t)
{
	
	
	while((x!=10)&&(y!=10)){
		if((a[x][y]%2)!=0)
		{
			if(x==9)
			{
				x=0;
				y++;
			}
			else x++;
		}
		else {
			if(y==9)x++;
			else y++;
		}
		m++;
		t+=a[x][y];//نقطه ضعف برنامه   Worst part of plan, unused operation in the function
		


	}


	
}
void board(int (*array)	[10][10])
{
	
srand (time(0));
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++)
			(*array)[i][j]=(rand()%9000)+1000;
	}
}
		
void reset( int *array, int size) {
   for ( int i = 0; i < size; ++i ) {
      array[i] = 0;
   }
}
/****************************************************************
 Max Finder Function
 ****************************************************************/
int FindMaxArray(int f[10][10])
{
int i;
int max=f[0][0];
for(i=0;i<10;i++){
	for(int j=1;j<10;j++)
			{
				if (f[i][j]>max)
					max=f[i][j];
				}
}
return(max);
}



/******************************************************************
Min Finder Function
*******************************************************************/

int FindMinArray(int f[10][10])
{
	int i;
	int min=f[0][0];
	for(i=0;i<10;i++){
		for(int j=1;j<10;j++)
		{
			if(f[i][j]<min)
				min=f[i][j];
		}
	}
	return (min);
}
/******************************************************************/
void mouse(int a){
for(int i=0;i<65;i++)
	{
		gotoxy(i,10+a);
		cout<<"-C>";
		Sleep(20);
		system("cls");
	}
}

Last edited on


and IAUTNB.H
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

#include "stdafx.h"   // استفاده از پیش پردازنده برای فراخوانی توابع کتابخانه ای
#include <Windows.h>  //
#include <iostream>   // ورودی و خروجی
#include <conio.h>
#include <time.h>     // برای استفاده فراخواندن عدد تصادفی

using namespace std;




void quran()// تعریف تابع قرآن
{
	system("color A6");
	system("cls");
	srand(time(0));
	cout<<"\n";
	int cash;
	cash=(rand()%4);
	switch (cash)
	{
		case 0:cout<<"we offered the trust to the heavens, and the earth, and the mountains \n , but they refused to bear it, \n and were afraid of it,\n and the human carried it. surely, he is a harmdoer,\n and ignorant.";break;
		case 1:cout<<"nun. by the pen and that which they write";break;
		case 2:cout<<" Allah is the creator of all things, and of all things he is the guardian";break;
		case 3:cout<<"we have sent down iron in which there is great might and diverse benefit for people";break;
	default:cout<<"In the name of God";
			
	}
}


void gotoxy(int x, int y)  //    تعریف تابع مختصات
{
	HANDLE hConsoleOutput;
	COORD dwCursorPosition;
	cout.flush();
	dwCursorPosition.X = x;
	dwCursorPosition.Y = y;
	hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}

void border()//تعریف تابع کادر 
{
	
	for(int h=0;h<25;h++)
	{
		gotoxy(0,h);
		cout<<"*";
	}
    for(int h=0;h<25;h++)
	{
		gotoxy(79,h);
		cout<<"*";
	}
	for(int w=0;w<79;w++)
	{
		gotoxy(w,0);
		cout<<"*";
	}
	for(int w=0;w<79;w++)
	{
		gotoxy(w,24);
		cout<<"*";
	}

}
void border2()// تعریف تابع دومین کادر
{
	
	for(int h=1;h<23;h++)
	{
		gotoxy(1,h);
		cout<<"*";
	}
    for(int h=1;h<23;h++)
	{
		gotoxy(78,h);
		cout<<"*";
	}
	for(int w=1;w<78;w++)
	{
		gotoxy(w,1);
		cout<<"*";
	}
	for(int w=1;w<78;w++)
	{

		gotoxy(w,23);
		cout<<"*";
	}
}
void intro_u()// تعریف تابع معرف اطلاعات دانشگاه
{
	
	system("cls");
	system("color B4");
	border();
	border2();
	

    gotoxy(3,2);
    cout<<"                 Islamic Azad University Tehran North Branch "<<endl;  
    gotoxy(3,3);
    cout<<"			              89-90"<<endl;
    gotoxy(3,4);
    cout<<"                                   Group 14"<<endl;
    gotoxy(3,5);
    cout<<"                                  IAUTNB.COM"<<endl;
    gotoxy(3,6);
    cout<<"                            codeshodegan.iautnb.com"<<endl;
    Sleep(2500);  
	
    system("cls");
}
void show (char a[25])
{
	
	
	int j;
	for( j=0;j<25;j++){
		cout<<a[j];
		Sleep(50);
	}cout<<"\n";
}
void intro_g()
{

	char n1[25]="Amirreza Asadi",n2[25]="Hamed Esmaeil Panah",n3[25]="Arian Mostashari",n4[25]="Alireza Taherjoian";
	show(n1);
	show(n2);
	show(n3);
	show(n4);
}


How about instead of posting the entire program, you just post the snippet you're having trouble with? As far as I can tell, you're using it correctly.
Topic archived. No new replies allowed.