로또 추첨 빈도수 검사 코드

#include <iostream> // 콘솔 입출력
#include <stdlib.h> // 랜덤 모듈
#include <time.h> // 타임 추출
#include <string>
#include <CoreWindow.h>

using namespace std;

class LottoGame{

//1. 로또 게임을 만듬
//2. n회 진행 후 로또 번호의 빈도수를 출력함



};

void main(){


// 로또 번호를 저장할 배열 생성
int rottoBall[6] = { 0, };
// 로또 추출 번호 빈도수를 저장할 배열 생성.
int rottoCount[45] = { 0, };
// 시드 섞기
srand((unsigned int)time(NULL));

for (int i = 0; i < 100; i++){

//6회 반복
//i는 로또 배열의 인덱스
for (int i = 0; i < 6; i++){
// 임의 로또 번호 추출
int num = rand() % 45 + 1;
rottoBall[i] = num;

for (int j = 0; j < i; j++){
// 로또 번호 중복 검사
if (rottoBall[i] == rottoBall[j]){
i--;
}
}

}

// 로또 1회 게임에 대한 출력문.
for (int i = 0; i < 6; i++){
cout << rottoBall[i] << "\t";

//현재 로또 번호의 빈도수를 증가함.
rottoCount[rottoBall[i]-1]++;
}
cout << endl;
}

//  계산한 로또 빈도수 값을 출력
int i = 0;
while (i < 45)
{

cout << i + 1 << "번째 공 빈도수 : " << rottoCount[i] << endl;

i++;
}
}


--- 해당 내용 다시 복습할것.

댓글

이 블로그의 인기 게시물

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

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

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