로또게임 반복되는 숫자 체크 로직

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
#include <iostream> // 콘솔 입출력
#include <stdlib.h> // 랜덤 모듈
#include <time.h> // 타임 추출
#include <string>
#include <CoreWindow.h>
using namespace std;
class LottoGame{
public:
    int resultNum[6];// 결정된 6개의 숫자를 담을 배열.
    int playNum=0// 현재 뽑힌 번호를 담을 변수
    int findNum=0;
    int RollNumver(){
        int Roll = rand() % 10 + 1;
        return Roll;
    }
    void InputNumber(){
        int i = 0;
        for (i; i < 6; i++){
            playNum = RollNumver(); // 6번 반복하면서 랜덤한 숫자를 playNum에 넣어주고
             cout << i << "번째 번호 : "<<playNum << endl;
             Sleep(1000);
            resultNum[i] = playNum; // 입력된 playNum 번호를 배열의[i]번째에 넣어준다.
            for (int j = 0; j < i; j++){ // 반복된 숫자 체크
                if (resultNum[j] == playNum){ // i번째 배열에 들어간 수가 playnum과 같으면 반복문을 재 실행 하도록 한다.
                    //cout << playNum << endl;
                    cout << i << "번째 번호 : " << playNum << "반복이므로 다시 체크 합니다." << endl;
                    i = i-1;
                }
            }            
            }        
    }
    void GameMain(){
        InputNumber();        
    }
};
void main(){
    srand((unsigned int)time(NULL));
    
    LottoGame myLottoGame;
    myLottoGame.GameMain();
}
cs

댓글

이 블로그의 인기 게시물

날짜 시간 시간차 시간 계산 하기

코루틴에서 CallBack 함수 적용하기

C++ 언어 퍼센트 구하는 방법 / 기본 언어 퍼센트 구하는 방법