본문 바로가기

카테고리 없음

로또 추첨기(배열사용)

반응형

#include <iostream>
#include<stdlib.h>
#include<time.h>
#include<iomanip>
#include<windows.h>
using namespace std;
int main(void)
{
--
로또에 사용될 변수 선언
--
int UNumber[45]={0},Lotto[45]={0};
int Count=0;//로또번호 맞춘 개수 카운터
int section=1;//로또 회수
int select;//메뉴 선택 변수
int UInputNumber;//입력받을변수
int dest,src;//처음번호와 마지막 번호를 바꾸기 위해사용될 변수
int bonus;//보너스 번호 
int Max=6;//로또번호 개수
while (true)
{//1번 while 문 시작
system("cls");
cout<<"\t\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣"<<endl;
cout<<"\t\t▣┌──────────────────┐▣"<<endl;
cout<<"\t\t▣│           로또 번호 생성           │▣"<<endl;
cout<<"\t\t▣│                                    │▣"<<endl;
cout<<"\t\t▣│             1.수동입력             │▣"<<endl;
cout<<"\t\t▣│             2.자동입력             │▣"<<endl;
cout<<"\t\t▣│             3.결    과             │▣"<<endl;
cout<<"\t\t▣│             0.종    료             │▣"<<endl;
cout<<"\t\t▣└──────────────────┘▣"<<endl;
cout<<"\t\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣"<<endl<<endl;
cout<<"\t\t▣ 메뉴 선택 : ";
cin>>select;//메뉴 선택
if (select >= 4)//메뉴번호외의 숫자를 입력시
{
while (true)//2번 while 문 시작
{
system("cls");
cout<<"\t\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣"<<endl;
cout<<"\t\t▣┌──────────────────┐▣"<<endl;
cout<<"\t\t▣│           로또 번호 생성           │▣"<<endl;
cout<<"\t\t▣│                                    │▣"<<endl;
cout<<"\t\t▣│             1.수동입력             │▣"<<endl;
cout<<"\t\t▣│             2.자동입력             │▣"<<endl;
cout<<"\t\t▣│             3.결    과             │▣"<<endl;
cout<<"\t\t▣│             0.종    료             │▣"<<endl;
cout<<"\t\t▣└──────────────────┘▣"<<endl;
cout<<"\t\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣"<<endl<<endl;
cout<<"\t\t▣ 메뉴 선택 : ";
cin>>select;
--메뉴에 있는 숫자를 입력시 체크 --
if (select<4)
{
break;
}
}//2번 while 문 종료
}
//메뉴 입력시 수행
switch (select)
{
case 1://수동 입력
{
int i,j;
system("cls");
cout<<"\t\t┏━━━━━━━━━━━━━━━━━━━━┓"<<endl;
cout<<"\t\t┃        ▣  로 또 번 호 입 력  ▣       ┃"<<endl;
cout<<"\t\t┗━━━━━━━━━━━━━━━━━━━━┛"<<endl;
for (i=0;i<Max;i++)//6개의 숫자를 배열에 입력
{
cout<<"\t\t▣"<<i+1<<"번 ";
cin>>UInputNumber;
if (UInputNumber ==0 || UInputNumber>=46)//입력숫자가 0 이거나 45보다 큰수일경우
{
while(UInputNumber ==0 || UInputNumber>=46)//0이거나 45보다 큰수를 입력하는동안 반복(0이아니거나46보다작은수를 입력할때까지)
{
system("cls");
cout<<"\t\t┏━━━━━━━━━━━━━━━━━━━━┓"<<endl;
cout<<"\t\t┃        ▣  로 또 번 호 입 력  ▣       ┃"<<endl;
cout<<"\t\t┗━━━━━━━━━━━━━━━━━━━━┛"<<endl;
cout<<"\t\t▣"<<i+1<<"번 ";
cin>>UInputNumber;
}
}
UNumber[i]=UInputNumber;
for (j=0;j<i;j++)///배열에 저장된 수중에서 중복수가 있는지 검사하기위해 처음부터 현재입력된배열위치까지 탐색 
{
if (UNumber[i] == UNumber[j])//만일 중복수가 있다면  i값을 감소시켜 그 전 값을 다시 입력받도록 한다.
{
i--;
break;
}
}
}
system("cls");
cout<<"\t\t┏━━━━━━━━━━━━━━━━━━━━┓"<<endl;
cout<<"\t\t┃        ▣  입 력 번 호 결 과  ▣       ┃"<<endl;
cout<<"\t\t┗━━━━━━━━━━━━━━━━━━━━┛"<<endl;
cout<<"\t\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣"<<endl;
cout<<"\t\t";
for (int k=0;k<6;k++)//입력된 번호를 출력
{
cout<<UNumber[k]<<"┃"<<"    ";
}
Sleep(3000);
}
break;
case 2://자동 입력
{
system("cls");
cout<<"\t\t┏━━━━━━━━━━━━━━━━━━━━┓"<<endl;
cout<<"\t\t┃        ▣  번 호 자 동 입 력  ▣       ┃"<<endl;
cout<<"\t\t┗━━━━━━━━━━━━━━━━━━━━┛"<<endl;
srand((unsigned int )time(NULL));
for (int i=0;i<sizeof(UNumber)/sizeof(UNumber[0]);i++)//sizeof(a)/sizeof(a[0])//배열의 개수계산
{
UNumber[i] =i+1;
}
for (int i=0;i<sizeof(UNumber)/sizeof(UNumber[0]);i++)
{
for (int j=0;j<10;j++)//10번섞기 위하여 
{
dest = rand()%sizeof(UNumber)/sizeof(UNumber[0]);
src = rand()%sizeof(UNumber)/sizeof(UNumber[0]);
//번호 섞기,위치를 바꿔줌
int temp = UNumber[src];
UNumber[src]=UNumber[dest];
UNumber[dest]=temp;
}
}
system("cls");
cout<<"\t\t┏━━━━━━━━━━━━━━━━━━━━┓"<<endl;
cout<<"\t\t┃        ▣  자 동 입 력 결 과  ▣       ┃"<<endl;
cout<<"\t\t┗━━━━━━━━━━━━━━━━━━━━┛"<<endl;
cout<<"\t\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣"<<endl;
cout<<"\t\t";
for (int k=0;k<Max;k++)//자동입력된 번호를 출력(6개만 출력)
{
cout<<UNumber[k]<<"┃"<<"    ";
}
Sleep(1000);
}
break;
case 3://결과
{
--로또 번호 생성--
srand((unsigned int )time(NULL));
for (int i=0;i<sizeof(Lotto)/sizeof(Lotto[0]);i++)//1~45개의 수를 차례대로 넣는다,sizeof(a)/sizeof(a[0])//배열의 개수계산
{
Lotto[i] =i+1;
}
for (int i=0;i<sizeof(Lotto)/sizeof(Lotto[0]);i++)
{
for (int j=0;j<10;j++)//10번섞기 위하여 
{
dest = rand()%sizeof(Lotto)/sizeof(Lotto[0]);
src = rand()%sizeof(Lotto)/sizeof(Lotto[0]);
//번호 섞기,위치를 바꿔줌
int temp = Lotto[src];
Lotto[src]=Lotto[dest];
Lotto[dest]=temp;
}
}
system("cls");
cout<<"\t\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣"<<endl;
cout<<"\t\t▣┌──────────────────┐▣"<<endl;
cout<<"\t\t▣│           로또 추첨 결과           │▣"<<endl;
cout<<"\t\t▣└──────────────────┘▣"<<endl;
cout<<"\t\t▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣▣"<<endl<<endl;
cout<<"\tSGA_LOTTO "<<section<<"회:: ";
for (int k=0;k<Max;k++)// 번호를 출력(6개만 출력)
{
cout<<Lotto[k]<<"┃"<<"  ";
}
//보너스 번호
bonus=rand()%45+1;
cout<<"보너스번호::"<<bonus<<endl<<endl;
cout<<"\t 입력번호 "<<section<<"회:: ";
for (int k=0;k<Max;k++)// 번호를 출력(6개만 출력)
{
cout<<UNumber[k]<<"┃"<<"  ";
}
cout<<endl<<endl;
--로또 번호 체크--
cout<<"\t\t 당첨번호::";
for (int i=0;i<Max;i++)//유저의 번호
{
for (int j=0;j<Max;j++)//로또번호
{
if (UNumber[i]==Lotto[j])//동일한 번호가 있을시 count 값을 증가
{
cout<<UNumber[i]<<" ";
Count++;
}
}
}
if (Count==0)
{
cout<<"한개도 없음";
}
cout<<endl<<endl;
cout<<"\t\t::당첨개수:: "<<Count<<"개"<<endl;
for (int i=0;i<Max;i++)
{
if(UNumber[i]==bonus)//같은 보너스 번호가있는지체크
{
cout<<"\t\t::당첨보너스::"<<UNumber[i]<<endl;
break;
}
}
//Count=6;
//6개의 번호를 모두 맞힌경우
if (Count == 6)
{
for(int i=0;i<100;i++)
{
system("cls");
cout<<"\t\t                          .*        "<<endl; 
cout<<"\t\t      *.                            "<<endl; 
cout<<"\t\t              .*            .*      "<<endl; 
cout<<"\t\t     *.                        .*   "<<endl; 
cout<<"\t\t       *.             .*            "<<endl;
cout<<"\t\t     *.     *.┏┓┏┓.*축    .*    "<<endl; 
cout<<"\t\t            ┏┻┫┣┻┓하          "<<endl; 
cout<<"\t\t     *.     ┃━┫┣━┃해      .*  "<<endl; 
cout<<"\t\t            ┃━┫┣━┃요~         "<<endl; 
cout<<"\t\t        *.  ┗━┛┗━┛            "<<endl; 
cout<<"\t\t                                    "<<endl; 
cout<<"\t\t           *.                       "<<endl; 
cout<<"\t\t            *.             .*       "<<endl; 
}
cout<<"\t\t┏━━━━━━━━━━━━━━━━━━━━┓"<<endl;
cout<<"\t\t┃▣ 당첨금 100,000,000,000,000,000.원 ▣ ┃"<<endl;
cout<<"\t\t┗━━━━━━━━━━━━━━━━━━━━┛"<<endl;
}
else
cout<<endl<<endl;
cout<<"\t\t┃                                          ┃"<<endl;
cout<<"\t\t┃                 ●┳━┓                 ┃"<<endl;
cout<<"\t\t┃                   ┛  ┗                 ┃"<<endl;
cout<<"\t\t┃                  ■■■■                ┃"<<endl;
cout<<"\t\t┏━━━━━━━━━━━━━━━━━━━━┓"<<endl;
cout<<"\t\t┃▣ 당첨금 000,000,000,000,000,000.원 ▣ ┃"<<endl;
cout<<"\t\t┗━━━━━━━━━━━━━━━━━━━━┛"<<endl;
section++;//로또 회수 증가
Count=0;
--for (int i=0;i<45;i++)
{
Lotto[i]=0;
}--
Sleep(7000);
}
break;
case 0://종료
{
system("cls");
cout<<"\t\t┏━━━━━━━━━━━━━━━━━━━━┓"<<endl;
cout<<"\t\t┃   ▣ 로또 생성기 를 종료 합니다.  ▣   ┃"<<endl;
cout<<"\t\t┗━━━━━━━━━━━━━━━━━━━━┛"<<endl;
}
break;
}//switch 문 종료
if (select ==0)//select=0 일시 종료
{
break;
}
}//1번 while 문 종료
return 0;
}

반응형