#include <iostream>
#include <ctime>
using namespace std;
/*
7개의 변수를 선언.
변수들에 1~7범위의 난수를 대입.
if문을 통해 중복된 숫자가 나올 경우 반복반복
모든값을 다뽑았으면 출력!
*/
int main(void)
{
int iLotto1=0, iLotto2=0, iLotto3=0, iLotto4=0, iLotto5=0, iLotto6=0, iLotto7=0; //로또번호를 담을 변수들
srand( (unsigned int)time(NULL) );//랜덤한 시드를 부여
iLotto1 = ( rand() %7 ) +1;
iLotto2 = ( rand() %7 ) +1;
iLotto3 = ( rand() %7 ) +1;
iLotto4 = ( rand() %7 ) +1;
iLotto5 = ( rand() %7 ) +1;
iLotto6 = ( rand() %7 ) +1;
iLotto7 = ( rand() %7 ) +1;
while(1)
{
if(iLotto2 == iLotto1)
{
iLotto2 = ( rand() %7 ) +1;
continue;
}
else if( iLotto3 == iLotto2 || iLotto3 == iLotto1 )
{
iLotto3 = ( rand() %7 ) +1;
continue;
}
else if( iLotto4 == iLotto3 || iLotto3 == iLotto2 || iLotto4 == iLotto1 )
{
iLotto4 = ( rand() %7 ) +1;
continue;
}
else if( iLotto5 == iLotto4 || iLotto5 == iLotto3 || iLotto5 == iLotto2 || iLotto5 == iLotto1 )
{
iLotto5 = ( rand() %7 ) +1;
continue;
}
else if( iLotto6 == iLotto5 || iLotto6 == iLotto4 || iLotto6 == iLotto3 || iLotto6 == iLotto2 || iLotto6 == iLotto1 )
{
iLotto7 = ( rand() %7 ) +1;
continue;
}
else if( iLotto7 == iLotto6 || iLotto7 == iLotto5 || iLotto7 == iLotto4 || iLotto7 == iLotto3 || iLotto7 == iLotto2 || iLotto7 == iLotto1 )
{
iLotto7 = ( rand() %7 ) +1;
continue;
}
else
{
break;
}
}
cout << iLotto1 << endl
<< iLotto2 << endl
<< iLotto3 << endl
<< iLotto4 << endl
<< iLotto5 << endl
<< iLotto6 << endl
<< iLotto7 << endl;
return 0;
}
로또번호생성기인데
이게 웃긴게 cout이 출력됬다가 안됬다가
아무 수정없이 함 컴파일할떄마다 뜰때도있고 안뜰때도있음
랜덤수를 뽑으려고하니까 출력도 랜덤으로됨 ㅋㅋ 허참
이거땜에 몇시간째 잡고씨름중인데 내실력으로 도저히 뭐때문에 버그가나는지 알수가없음.. 컴파일할때도 에러뜨는거 하나도없고
으아아ㅏ제발도와주세여
else if에 위에꺼랑 같은 조건식이 들어가도 됌?
else if 용법이 좀 틀렸을것같은 기분이 든다
게다가 코드가 좀 많이 이상한데.. 꼼꼼히 살펴봐
ㄴ형말듣고 iLotto3 == iLotto2 여기가 오타난거찾아서고쳤는데 여전히똑같아..흑흑 다시찾아볼게
값을 뽑아서 배열에 저장하고 배열 인덱스 하나씩 올리면서 값하나 넣고 중복체크 중복일 경우엔 인덱스 줄여서 다시 값 받고 하는식으로..
과제가 배열안쓰고해오는거라..
으어찾았다
else if( iLotto6 == iLotto5 || iLotto6 == iLotto4 || iLotto6 == iLotto3 || iLotto6 == iLotto2 || iLotto6 == iLotto1 ) { iLotto7 = ( rand() %7 ) +1; continue;
여기가범인이었네 ㅋㅋㅋㅋㅋㅋㅋㅋㅋ으엌ㅋㅋㅋㅋㅋㅋㅋ
727형 고마움 덕분에찾음 ㄳㄳ
굳