hello i need help to my lottery number

as you know the lottery numbers occurs a specific number and sequence. i have problem with the number creating. İ don't want same numbers and for this i developped a function for this but i cant get this done. i need your feedbacks

this is the program
#include <cstdlib>
#include <iostream>
#include <stdio.h> // Srand için
#include <time.h> // time fonksiyonu için

using namespace std;
int karar=0;
int sayikontrol(int kontrol[]);
int karsilastir(int karsilasma[]);
int main(int argc, char *argv[])
{

cout<<"Sayisal loto"<<endl;
srand(time(NULL));

int sayi,random, temp1,temp2,temp3,x;
int sayiDizisi[6];

do
{
for(int i=0;i<6;i++)
{
random = rand()%49+1;

//for(int k=0;k<20000000;k++) {}

sayiDizisi[i]=random;

x=sayikontrol(sayiDizisi); // x for check the numbers and if any number same in array do randomize again until all of them different

}
cout<<karar<<endl; //for see program how many times used fonction
}while(x!=1);




karsilastir( sayiDizisi) ; // function call for order to numbers

cout<<endl;

for(int i=0;i<6;i++)
{
cout<<sayiDizisi[i]<<" ";
}


system("PAUSE");
return EXIT_SUCCESS;
}
/*---------------------------------------------------------------------*/
int karsilastir(int karsilasma[6]) // function for order to numbers
{
int gecici;

for(int k=0; k<5; k++){
for(int j=0; j<5; j++)
{
if( karsilasma[j]>karsilasma[j+1] ){
gecici = karsilasma[j];
karsilasma[j] = karsilasma[j+1];
karsilasma[j+1] = gecici;
}
}
}

return karsilasma[6];
}
/*---------------------------------------------------------------------*/


int sayikontrol(int kontrol[6]) // this function for compare to numbers
{
for(int i=5;i>0;i--)
{

for(int j=0;j<i;j++)
{
if(kontrol[j]==kontrol[i])
{
karar=1;
}
else
{
karar=0;
}



}
}
return karar;

}
remove the "else" clause, or put return 1; inside if(== )
because when u have numbers like 0 0 1 2 3 4 , the " 1" would've been overwritten

please use [code] whenever u paste.

( and btw use english names for ur variables its good practice. )
thank you NtSzar. i realise a mistake in do while loop i fixed. if i delete else in thisfunction" int karsilastir(int karsilasma[6])" sends always "0" and the loop that creating randomize transforms into an infinite loop. so alhough fixed my mistake if slight i get same numbers that neighbours values for ex " 8-12-28-35-35-42. i couldnt fixed problem i thinked include strcmp in fonction but i belive i can fix the problem without this. f9 this program many times u will see the same numbers.

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


#include <cstdlib>
#include <iostream>
#include <stdio.h> // Srand için
#include <time.h>   // time fonksiyonu için

using namespace std;
int karar=0;
int sayikontrol(int kontrol[]);
int karsilastir(int karsilasma[]);
int main(int argc, char *argv[])
{
   
   cout<<"Sayisal loto"<<endl;
  srand(time(NULL));

    int sayi,random, temp1,temp2,temp3,x;
    int sayiDizisi[6];
    /*---------------------------------------------------------------------------------------*/
    do
     {
               for(int i=0;i<6;i++)
       {
               random = rand()%49+1;
          
               //for(int k=0;k<20000000;k++) {}
          
               sayiDizisi[i]=random; 
         
               x=sayikontrol(sayiDizisi);     // x for check the numbers and if any number same in array do randomize again until all of them different
    
       }
   cout<<karar<<endl; //for see program how many times used fonction
   }while(x!=1);
   
     /************************************************************************************************/
   
  
    karsilastir( sayiDizisi)  ;  // function call for order to numbers
    
     cout<<endl;
    
     for(int i=0;i<6;i++)
    {  
     cout<<sayiDizisi[i]<<" ";
    }
 
 
    system("PAUSE");
    return EXIT_SUCCESS;
}
/*---------------------------------------------------------------------*/
int karsilastir(int karsilasma[6])  // function for order to numbers
  {
     int gecici;
     
    for(int k=0; k<5; k++){
   for(int j=0; j<5; j++)
   {
      if( karsilasma[j]>karsilasma[j+1] ){
         gecici = karsilasma[j];
           karsilasma[j] = karsilasma[j+1];
         karsilasma[j+1] = gecici;
      }
      }
      }
              
                    return karsilasma[6];
  }
/*---------------------------------------------------------------------*/


int sayikontrol(int kontrol[6])   // this function for compare to numbers
{
    for(int i=5;i>0;i--)
    {
              
            for(int j=0;j<i;j++)
               {
                    if(kontrol[j]==kontrol[i])
                    {
                    karar=0;
                    }      
                   else
                    {
                        karar=1;
                    }        
                    
                        
    
     }
    }     
    return karar;

}
Last edited on
dear friensd i fixed my problem first changed place karar variable position into function, for function variable. remove the else in "int sayikontrol(int kontrol[6])" and changed karar=0 to karar = 1 and add break under karar=1. so i fixed.
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
#include <cstdlib>
#include <iostream>
#include <stdio.h> // Srand için
#include <time.h>   // time fonksiyonu için

using namespace std;

int sayikontrol(int kontrol[]);
int karsilastir(int karsilasma[]);
int main(int argc, char *argv[])
{
   
   cout<<"Sayisal loto"<<endl;
  srand(time(NULL));

    int sayi,random, temp1,temp2,temp3,x;
    int sayiDizisi[6];
    /*---------------------------------------------------------------------------------------*/
    do
     {
               for(int i=0;i<6;i++)
       {
               random = rand()%49+1;
          
               for(int k=0;k<20000000;k++) {}
          
               sayiDizisi[i]=random; 
         
               x=sayikontrol(sayiDizisi);     // x for check the numbers and if any number same in array do randomize again until all of them different
    
       }
   cout<<x<<endl; //for see program how many times used fonction
   }while(x==1);
   
     /************************************************************************************************/
   
  
    karsilastir( sayiDizisi)  ;  // function call for order to numbers
    
     cout<<endl;
    
     for(int i=0;i<6;i++)
    {  
     cout<<sayiDizisi[i]<<" ";
    }
 
 
    system("PAUSE");
    return EXIT_SUCCESS;
}
/*---------------------------------------------------------------------*/
int karsilastir(int karsilasma[6])  // function for order to numbers
  {
     int gecici;
     
    for(int k=0; k<5; k++){
   for(int j=0; j<5; j++)
   {
      if( karsilasma[j]>karsilasma[j+1] ){
         gecici = karsilasma[j];
           karsilasma[j] = karsilasma[j+1];
         karsilasma[j+1] = gecici;
      }
      }
      }
              
                    return karsilasma[6];
  }
/*---------------------------------------------------------------------*/


int sayikontrol(int kontrol[6])   // this function for compare to numbers
{
    int karar=0; 
    for(int i=5;i>0;i--)
    {
            
            for(int j=0;j<i;j++)
               {
                    if(kontrol[j]==kontrol[i])
                    {
                    karar=1;
                    break;
                    }      
                }
    
    }     
    return karar;

}



/*
for(k=0; k<n-1; k++)
   for(j=0; j<n-1; j++)
      if( a[j]<a[j+1] ){
         gecici = a[j];
           a[j] = a[j+1];
         a[j+1] = gecici;
      }
*/







/*int karsilastir(int karsilasma[6])
  {
      for(int i=0;i<5;i++)
      { 
             for(int j=1;j<=5;j++)
             {
                 
                 if(karsilasma[4]>karsilasma[])
                   {
                   int temp1=karsilasma[j];
                   karsilasma[j]=karsilasma[i];
                   karsilasma[i]=temp1;
                   }              
                   
                }  
              
                    return karsilasma[6];     */
Topic archived. No new replies allowed.