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
system("PAUSE");
return EXIT_SUCCESS;
}
/*---------------------------------------------------------------------*/
int karsilastir(int karsilasma[6]) // function for order to numbers
{
int gecici;
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.
#include <cstdlib>
#include <iostream>
#include <stdio.h> // Srand için
#include <time.h> // time fonksiyonu için
usingnamespace 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;
}
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.
#include <cstdlib>
#include <iostream>
#include <stdio.h> // Srand için
#include <time.h> // time fonksiyonu için
usingnamespace 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]; */