Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- int menu(void);
- int lotto(int *cnt);
- int numlist(int *cnt);
- int numgraph(int *cnt);
- int rdnum_p(int *lotto_num);
- int graph_p(int *g_num);
- int pause(int err);
- int end(void);
- struct lotto_db{int n1;int n2;int n3;int n4;int n5;int n6;};
- struct lotto_db table[1000]; //숫자값을 지우면 무제한...은 가능하나 Warning. 헌데 1000까지 갈련지는...
- int main(void)
- {
- menu();
- end();
- }
- int menu(void)
- {
- srand((unsigned long)time(NULL));
- int cnt=0, sele;
- while(1)
- {
- system("clear");
- printf("============로또자동추첨프로그램v1============\n");
- printf("1)추첨 2)회차별_번호확인 3)번호확률현황 4)종료\n");
- printf("==============================================\n");
- printf(">");
- scanf("%d", &sele);
- if(sele==1) lotto(&cnt);
- else if(sele==2) numlist(&cnt);
- else if(sele==3) numgraph(&cnt);
- else if(sele==4) break;
- else pause(1);
- }
- }
- int lotto(int *cnt)
- {
- system("clear");
- int lotto_num[6];
- if(*cnt==1000) printf("더이상 조회가 안되요.\n");
- else
- {
- rdnum_p(lotto_num);
- table[*cnt].n1 = lotto_num[0];
- table[*cnt].n2 = lotto_num[1];
- table[*cnt].n3 = lotto_num[2];
- table[*cnt].n4 = lotto_num[3];
- table[*cnt].n5 = lotto_num[4];
- table[*cnt].n6 = lotto_num[5];
- printf("로또번호가 생성되었습니다. 추가생성가능한 횟수는 %d회입니다.\n", 999-*cnt);
- printf("|%d|%d|%d|%d|%d|%d|\n", table[*cnt].n1,table[*cnt].n2,table[*cnt].n3,table[*cnt].n4,table[*cnt].n5,table[*cnt].n6);
- *cnt+=1;
- }
- pause(0);
- }
- int numlist(int *cnt)
- {
- system("clear");
- if(*cnt==0) pause(4);
- else
- {
- printf("현재까지 생성한 로또번호는 아래와 같습니다.\n");
- printf("------------------------\n");
- for(int c_cnt=0; c_cnt<*cnt; c_cnt++)
- {
- if(c_cnt<9)printf("|000%d|",c_cnt+1);
- else if(c_cnt<99) printf("|00%d|",c_cnt+1);
- else if(c_cnt<999) printf("|0%d|",c_cnt+1);
- else printf("|%d|",c_cnt+1);
- printf("%d/%d/%d/%d/%d/%d\n",table[c_cnt].n1,table[c_cnt].n2,table[c_cnt].n3,table[c_cnt].n4,table[c_cnt].n5,table[c_cnt].n6);
- }
- printf("------------------------\n");
- pause(0);
- }
- }
- int numgraph(int *cnt)
- {
- system("clear");
- int temp_num=0,g_num[45];
- for(int g_clr=0;g_clr<45;g_clr++) //g_num 숫자클리어
- {
- g_num[g_clr] = 0;
- }
- if(*cnt==0) pause(4);
- else
- {
- for(int g_cnt=0;g_cnt<*cnt;g_cnt++)
- {
- temp_num = table[g_cnt].n1;
- g_num[temp_num-1]+=1;
- temp_num = table[g_cnt].n2;
- g_num[temp_num-1]+=1;
- temp_num = table[g_cnt].n3;
- g_num[temp_num-1]+=1;
- temp_num = table[g_cnt].n4;
- g_num[temp_num-1]+=1;
- temp_num = table[g_cnt].n5;
- g_num[temp_num-1]+=1;
- temp_num = table[g_cnt].n6;
- g_num[temp_num-1]+=1;
- }
- printf("한번도 출력되지 않는 숫자는 그래프에서 제외됩니다. :)\n");
- printf("-------\n");
- graph_p(g_num);
- }
- pause(0);
- }
- int rdnum_p(int *lotto_num)
- {
- int p_cnt=0, ec_cnt=0;
- int temp_num ;
- while(p_cnt<6)
- {
- int cksum=0;
- //숫자를 골고루 섞자. 누가 랜덤을 돌린 두번째번호가 45이라고하는 끔직한 생각을 했느냐.
- /*if (p_cnt==5)temp_num = (rand()%44)+1;
- else if (p_cnt==4)temp_num = (rand()%43)+1;
- else if (p_cnt==3)temp_num = (rand()%42)+1;
- else if (p_cnt==2)temp_num = (rand()%41)+1;
- else if (p_cnt==1)temp_num = (rand()%39)+1;
- else temp_num = (rand()%19)+1;
- */
- //printf("%d//뛰어쓰기나나\n",temp_num);
- temp_num = (rand()%45)+1;
- for(int r_cnt=0;r_cnt<p_cnt;r_cnt++)
- {
- if(lotto_num[r_cnt]==temp_num) cksum=1;
- else if(temp_num<lotto_num[p_cnt-1]) cksum=2;
- else if(temp_num>45) cksum=3;
- else cksum = 0;
- }
- if (cksum==0)
- {
- lotto_num[p_cnt] = temp_num;
- p_cnt++;
- }
- ec_cnt++;
- if(ec_cnt==100){ec_cnt=0; p_cnt=0;} //Stop Endless Circulation.
- }
- }
- int graph_p(int *g_num)
- {
- for(int p_cnt=0;p_cnt<45;p_cnt++)
- {
- if(g_num[p_cnt]>0)
- {
- if(p_cnt<9)printf("|0%d",p_cnt+1);
- else printf("|%d",p_cnt+1);
- if(g_num[p_cnt]<10)printf("|00%d|",g_num[p_cnt]);
- else if(g_num[p_cnt]<100)printf("|0%d|",g_num[p_cnt]);
- else printf("|%d|",g_num[p_cnt]);
- for(int pp=0;pp<g_num[p_cnt];pp++)
- {
- printf("■");
- }
- printf("|\n");
- }
- }
- }
- int pause(int err)
- {
- char p_dummy[100];
- if(err==1){system("clear"); printf("잘못된 값을 입력했습니다.");}
- if(err==2){system("clear"); printf("같은값을 찾을수가 없습니다.");}
- if(err==3){system("clear"); printf("삭제되었습니다.\n");}
- if(err==4){system("clear"); printf("DB에 아무련번호가 없어요. 만들어주세요.\n");}
- if(err==5){system("clear"); printf("미구현\n");}
- printf("\n-------");
- printf("\n계속하실려면 아무글자나 입력후 엔터를 눌려주세요.\n");
- scanf("%s", p_dummy);
- strcpy(p_dummy, " ");
- }
- int end(void)
- {
- system("clear");
- printf("프로그램을 종료합니다.\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement