'C/C++'에 해당되는 글 26건

  1. 2009.03.24 다중 포인터
  2. 2009.03.24 야구게임
  3. 2009.03.19 포인터
  4. 2009.03.19 배열
  5. 2009.03.19 피보나치 수열
  6. 2009.03.19 함수, 지역변수, 전역변수, 재귀함수
  7. 2009.03.19 블랙잭 게임 [미완성]
  8. 2009.03.19 베스킨라빈스 31 게임
  9. 2009.03.19 Dice Game
  10. 2009.03.19 UP & Down Game
C/C++2009. 3. 24. 20:47

/*
#include <stdio.h>   //2차원 배열

int main(void){

 int A[3][4] = {
  {1,2,3,4},
  {5,6,7,8},
  {9,10,11,12}

 };
 int i,j;

 printf("A[0][0] = %d \n",A[0][0]);
 printf("A[0][0] = %d \n",A[1][3]);

 printf("A = %d \n",A);
 printf("A[0] = %d \n",A[0]);
 printf("&A[0][0] = %d \n",&A[0][0]);
 printf("A[1] = %d \n",A[1]);
 printf("&A[1][0] = %d \n",&A[1][0]);

 for(i=0;i<3;i++){
  for(j=0;j<4;j++){
   printf("%3d ",A[i][j]);
  }
  printf("\n");

 }

 return 0;
}
*/

/*

#include <stdio.h>   //2차원배열을 이용 학생성적

int main(void){

 int A[3][4];
 int i,j;

 printf("<<학생 성적 입력>>\n");

 for(i=0;i<3;i++){
  printf("<< %d번째 학생>>\n",i+1); 
  printf(" 국어 : ");
  scanf("%d",&(A[i][0]));  //표를 생각해보면 됨
  printf(" 영어 : ");
  scanf("%d",&(A[i][1]));
  printf(" 수학 : ");
  scanf("%d",&(A[i][2]));
  A[i][3]=A[i][0]+A[i][1]+A[i][2];  //for이 세번 돌면서 합까지 열3번째 계산
 }
  
 
  printf("%s %5s %5s %5s %5s\n","Num","국어","영어","수학","합계");
  
  for(i=0;i<3;i++){
   printf("[%d]",i+1);
   for(j=0;j<4;j++){
    printf("%5d", A[i][j]);
   }
   printf("\n");
  }
  return 0;
}
*/

#include <stdio.h>

int main(){

 int x = 10;

 int * p;    //일중 포인터
 int ** pp;   //이중 포인터
 int *** ppp;   //삼중 포인터
 int y = 200;

 p = &x;

 *p = 100;

 printf("x = %d \n",x);   //x의값
 printf("&x = %d \n",&x); //x의 주소

 pp = &p;

 printf("pp = %d \n",pp);  //p의 주소
 printf("*pp = %d \n",*pp);  //2번따라가서 x의 주소
 printf("**pp = %d \n",**pp); //x의 값

 ppp = &p;
 printf("ppp = %d \n",ppp);
 printf("*ppp = %d \n",*ppp);
 printf("**ppp = %d \n",**ppp);
 //printf("***ppp = %d \n",***ppp);

 x = &y;

 printf("***ppp = %d \n",***ppp);

 return 0;
}

슬슬 한계다...

Posted by 샤키
C/C++2009. 3. 24. 20:45

#include <stdio.h>   //야구게임
#include <time.h>
#include <stdlib.h>

int main(){
 int Player[3];  //플레이어 숫자
 int CPU[3];  //컴퓨터 숫자
 int strike=0,ball=0,count=0;
 int i,j;
 int tmp;

 srand(time(NULL));
 rand();rand();rand();
 srand(rand());

 CPU[0]=rand()%9+1;  //랜덤수 생성
 CPU[1]=rand()%9+1;
 CPU[2]=rand()%9+1;


 while((CPU[0]==CPU[1])||(CPU[1]==CPU[2])||(CPU[0]==CPU[2])) //랜덤수가 중복 되지 않기 위해
 {
  CPU[0]=rand()%9+1;
  CPU[1]=rand()%9+1;
  CPU[2]=rand()%9+1;
 }


 printf("== 게임을 시작 합니다 ==\n"); 

 while(1){
  printf("= 숫자를 세개 입력하세요 = :");
  scanf("%d",&tmp);

  strike=0;
  ball=0;

  Player[0] = tmp/100;
  Player[1] = tmp%100/10;
  Player[2] = tmp%100%10;


  for(i=0;i<3;i++)  
   for(j=0;j<3;j++)
    if(CPU[i]==Player[j]&&i==j){
     strike++;      //스트라이크 맞춘갯수
    }else if(CPU[i]==Player[j]){
     ball++;       //자리는 안맞고 숫자만 맞춘갯수
    }


    count++;

    printf("%d번째  Strike: %d  Ball: %d\n",count,strike,ball);
    printf("\n");


    if(strike==3){        // 3개 모두 자리수 맞추면 끝
     printf("숫자는 %d, %d, %d 입니다\n",CPU[0],CPU[1],CPU[2]);
     printf("%d 번만에 맞추셨습니다!! \n",count);
     break;
    }

 }
}


Posted by 샤키
C/C++2009. 3. 19. 23:41
포인터란 메모리의 번지 주소이다.
포인터 변수는 메모리의 주소를 가지는 변수이다.
포인터 변수의 크기는 4byte의 부호없는 정수형이다

/*
포인터변수 = 포인터
변수 : 데이터를 담을수 있는 메모리
메모리주소를 담는 변수

☆포인터변수를 선언하면 ---> 부호없는 정수형 (4바이트)☆
*/

/*
#include <stdio.h>

int main(){

int x = 100;
int y = 200; 

int * p;

printf("x = %d \n", x);
printf("x의 주소 : %d \n", &x);       //10진수 %d,    16진수로 보려면 %x
printf("x의 16진수 : %x \n", &x);
printf("y = %d \n", y);
printf("y의 주소 : %d \n", &y);   // &변수의 주소
printf("y의 16진수 : %x \n", &y);

p = 1245024;       //&x  내 x의 메모리주소

printf("p = %d \n", p);     //p는 메모리주소를 담고 있고
printf("*p = %d \n", *p);    //*는 주소를 통해 해당변수로 접근
*p = 300;
printf("x = %d \n", x);


return 0;

}
*/


/*
int main(){

int Num = 0x12345678;
char * p;

p = &Num;

printf("Num = %x\n",Num);
printf("*p = %x \n",*p);      //char로 1바이트를 사용 그래서 두자리수씩 읽는데
// 엔디안방식(?)으로 실질적으로는 78 56 34 12로 나와서 78로 출력

return 0;

}
*/


/*
int main(){

int A[7] = { 10, 23, 51, 2, 990, 3, 94 }; 

double * p;       //double 이건 p는 부호없는 4바이트다

p = &A[1];

printf("%d",*(p+2));


return 0;
}
*/

/*
int main(){         //배열과 포인터

int A[8] = { 10, 23, 51, 2, 990, 3, 94, 0};  //A는 배열의 첫번째 주소(&A[0]과 같은뜻)
int * p; 


printf("*A = %d \n",*A);    //A는 포인터 상수 (값이 변경 불가능)☆중요
printf("*(A+1) = %d \n",*(A+1));  //10 다음수 23 출력

p = A;
printf("*p = %d \n",*p);    //p는 포인터 변수 (값이 변경 가능)☆중요
printf("*(p+1) = %d \n",*(p+1));


//p++;         //p가 포인터변수라서 가능 (반면, A++는 상수라 불가능)☆중요
//printf("*p = %d \n",*p);

for(p=A;*p != 0;p++){   //p는 A부터 p가 0이 아닐때까지 증가하면서 출력해라
printf("%d \n", *p);

}

 

return 0;
}

*/

/*
#include <stdio.h>      //Call by Reference

void func(int *x, int *y){          //주소로 넘겨준다
printf("x(main Num1 주소) = %d \n",x);
printf("y(main Num1 주소) = %d \n",y);


*x = 300;      //넘겨준 주소에서 값을 바꾸면
*y = 400;
}

int main(){
int Num1 = 100;
int Num2 = 200;

printf("Num1 = %d \n",Num1);
printf("Num1 = %d \n",Num2);

func(&Num1,&Num2);

printf("Num1 = %d \n",Num1);  //함수요청후 값이 바뀌걸 알수있다
printf("Num1 = %d \n",Num2);


return 0;
}

*/

/*
#include <stdio.h>     //두 값을 서로 교환하는 함수
void change(char *ch1, char *ch2){
 char tmp;
 tmp = *ch1;
 *ch1 = *ch2;
 *ch2 = tmp;

}
int main(){

 char x='A', y='B'; 
 printf("x = %c , y = % c\n",x,y);
 change(&x,&y);
 printf("x = %c , y = % c\n",x,y); 

 return 0;

}
*/

/*
#include <stdio.h>

int main(){

 int array[10] = {6,9,3,2,161,4,888,19};
 int *pt = array;

 printf("*array    : %d\n",*array);          //6
 printf("*array    : %d\n",*array+4);  //*array부터 계산
 printf("*array    : %d\n",*(array+2)); //3
 printf("*(pt+1)    : %d\n",*(pt+1));  //9
 printf("*(2+pt)+1   : %d\n",*(2+pt)+1);  //X
 printf("2*(*(4+(++pt))+5)  : %d\n",2*(*(4+(++pt))+5));
 printf("*5[array]   : %d\n",5[array]);
 printf("*array[5]   : %d\n",array[5]);
 printf("*0[array+5]   : %d\n",0[array+5]);
 printf("*(3+1)[array+1]+10  : %d\n",(3+1)[array+1]+10);
 printf("*1+2[array+3]+5   : %d\n",1+2[array+3]+5);

 return 0;

}
*/

#include <stdio.h>
int change(int *a,int *b,int c){

 int temp = *a;    //*a의 10을 백업
 *a = c;    //c의30을 *a에 복사
 c = *b;    //*b의 20을 c에 복사
 *b = temp;   //백업해둔 temp를 불러와 *b에 복사해서 *b는 10
 return c;   //c말고도 a,b로도 바꾸어본다
}
int main(){
 int a=10,b=20,c=30;
 c = change(&a,&b,c);
 printf("a : %d\n",a);
 printf("b : %d\n",b);
 printf("c : %d\n",c);
 return 0;
}


C의 꽃이라고 하는 포인터다 아직은 들을만 하다... 
놓치지 말고 열심히 해야지...
언제 포기 할지 모르지만...

Posted by 샤키
C/C++2009. 3. 19. 23:39

/*
#include <stdio.h>          //배열의 선언

int main(){

int x = 10;
int y = 20;
int i;
int Sum = 0;   // 초기값은 int Array[3] = { 100, 200, 300}; 사용할수 있다
// int Array[] = { 100, 200, 300};  이것처럼 초기값이 있으면 비울수도 있다

int Array[5];          //  int Array선언할때 [ ]고정된값(상수)를 사용 ; 변수는 에러남

printf("x = %d \n",x);
printf("y = %d \n",y);

printf("x = %d \n",&x);   //&메모리구조 보는
printf("y = %d \n",&y);

Array[0] = 100;

printf("Array[0] = %d \n",Array[0]);
printf("&Array[0] = %d \n",&Array[0]);
printf("Array = %d \n",Array);  //그냥 변수는 첫번재 0번 배열과 같다
printf("Array의 크기 : %d \n",sizeof(Array)); //변수의 크기

for(i=0;i<5;i++){   //for문을 이용 같은배열 사용
printf("%d번째 학생의 성적 입력 : ",i+1);
scanf("%d",&Array[i]);
Sum = Sum + Array[i];
}

for(i=0;i<5;i++){
printf("%d번째 학생 성적 : %d \n",i+1,Array[i]);
}
printf("==============================\n");
printf("학생의 전체 합은 %d \n",Sum);
printf("==============================\n");


}
*/


/*
#include <stdio.h>      //배열로 문자 다루기
int main(){

char String[10] = "apple";   //초기값 설정
char String1[10];
int i;
String1[0] = 'o';
String1[1] = 'r';
String1[2] = 'a';
String1[3] = 'n';
String1[4] = 'g';
String1[5] = 'e';
String1[6] = '\0';  //문자열 마지막에 NULL문자 삽입
printf("String = ");
for(i=0;i<sizeof(String);i++){
if(String[i]==NULL){break;}  //String[i]가 NULL문자일시 for문 종료
printf("%c",String[i]); 
}
printf("\nString1 = %s \n", String1);
return 0;
}
*/


/*
#include <stdio.h>       //배열을 이용 암호화, 복호화


int main(){

char ch[10] = "Apple";
int i;


for(i=0;i<10;i++){
ch[i] = ch[i]+3;   // 3씩 이동하여 암호화
}

printf("암호화 : %s \n",ch);

for(i=0;i<10;i++){
ch[i] = ch[i]-3;    // 3씩 이동한것을 다시 원상태로 해서 복호
}
printf("복호화 : %s \n",ch);

for(i=0;i<10;i++){
ch[i] = ch[i]^168642;   // 비대칭식으로 암호화
}

printf("암호화 : %s \n",ch);

for(i=0;i<10;i++){
ch[i] = ch[i]^168642;   // 그대로 다시 치면 복호
}

printf("복호화 : %s \n",ch);

}

*/

/*
#include <stdio.h>       //AB 순서를 배열로 이용 서로 부꾸기


int main(){

char ch[3] = "AB";
char tmp;

printf("%c  %c \n",ch[0],ch[1]);

tmp = ch[0];       //ch[0]을 tmp에 백업
ch[0] = ch[1];  // ch[1]을 ch[0]으로 복사
ch[1] = tmp;  // 다시 백업한 tmp를 불러옴


printf("%c  %c \n",ch[0],ch[1]);

}
*/

/*
#include <stdio.h>         // Reverse 문자열 출력


int main(){

char ch[] = "Reverse";
int i,j;
char tmp;

 

for (i=0;i<sizeof(ch);i++){  


printf("%s\n",ch);

tmp = ch[0];      //초기값 설정
for(j=0;j<6;j++){
ch[j] = ch[j+1];
}
ch[6] = tmp;       //백업한것을 다시 복귀

}

}
*/
/*    
#include <stdio.h>       //Reverse 문자열 반복
#include <windows.h>

int main(){

char ch[] = "Reverse  ";
int i,j;
char tmp;

 

while(1){         //무한반복


printf("%s\r",ch); //    /r  출력을 다시 처음으로 가라

tmp = ch[0];      //초기값 설정
for(j=0;j<6;j++){
ch[j] = ch[j+1];
}
ch[6] = tmp;       //백업한것을 다시 복귀
Sleep(100);   // 콘솔창에 출력속도(?)

}

}

*/
#include <stdio.h>       //배열을 이용 순서를 정리

int main(){

 int A[10] = { 30, 11, 55, 67, 99, 50, 39, 100 };
 int i,j;
 char tmp;

 for(i=0;i<10;i++){
  printf("[%2d] : ",i+1);   
  for(j=0;j<10;j++){
   printf("%d ",A[j]);
  }
  printf("\n");

  for(j=0;j<9;j++){   
   if(A[j]>A[j+1]){        //부등호 바꾸면 오름차순, 내림 차순 바꿀수 있다  
    tmp = A[j];
    A[j] = A[j+1];
    A[j+1] = tmp;     
   }
  }


 
 }

 

}

Posted by 샤키
C/C++2009. 3. 19. 23:36

#include<stdio.h>

int func(int i){
 static int data=1;
 if(data<1000){
  printf(" %d ",data);
  printf(" %d ",i);   
  data = data+i; 
  return func(data+i)+data;
 }
 return 0;
 
}


int main(){
 int i = 1; 
 func(i);
 printf("\n");
 printf("\n피보나치수열\n");
 return 0;

}





재귀함수를 사용하여 피보나치 수열을 작성한건데...
원한 답은 나왔지만
뭔가 찝찝...
Posted by 샤키
C/C++2009. 3. 19. 23:29

/*#include <stdio.h>

int C;   //전역변수

void func(int AA, int BB){   //지역변수

printf("func함수\n");
printf("AA = %d \n",AA);
printf("BB = %d \n",BB);
C = 100;

}

int main(){   //지역변수

int A = 10;
int B = 20; 

printf("A = %d \n",A);
printf("B = %d \n",B);
printf("C = %d \n",C);  //main 함수에서

func(A,B);

printf("C = %d \n",C);  //func 함수 갔다 와서

return 0;

}
*/

/*
#include <stdio.h>
int a = 9;
int func(int b, int c);
int finc1(int b);
int main(){
int b=3;       // b=3
int c=6;  // c=6
b=func(b,c);   //  //12가 되고
printf("%d\n",b);  //가장 나중에 출력
return 0;
}
int func(int b, int c)  //첫번째b=3,c=6
{
printf("%d\n",b);    //3
printf("%d\n",c); //6
b = 4;
func1(b);   //4일때 func1로 이동  --->
a = 21;
b = 6;
return b+b;    //12이니
}
int func1(int b)  //b=4
{
printf("%d\n",b);    //4로출력
printf("%d\n",a);  //전역변수 a가 9
return 9;
}
*/

/*
#include <stdio.h>

void func(void){
static int A=0;
A++;
if(A==7){
printf("이 문구는 일곱번째에서 출력 \n");

}
printf("A = %d \n", A);
}
int main(){
func();
func();
func();
func();
func();
func();
func();
func();
func();
func();

func();
func();
func();
func();
func();
func();
func();
func();
func();
func();
func();
func();
func();


return 0;
}
*/

#include <stdio.h>
#include <time.h>
int baserand(int x, int y){
 static int seed; 
 seed = rand()%(y-x+1)+x;
 return seed;
}
int main()
{
 printf("baserand함수 = %d \n",basdrand(10,20)); 
 return 0;
}


/*
#include <stdio.h>

int func(int data){
 if(data){
  printf("%d + ",data);
  return func(data-1)+data;
 }
 printf("\b\b= ");
 return 0;
}
int main()
{
 int i = 30;
 printf("%d\n", func(i));
 return 0;
}

*/
/*
#include <stdio.h>
int fibo(int data);
int main(void)
{
 int i,a;
 printf("피보나치 수열 출력\n");
 printf("몇번째 까지 출력 해 드릴까요? >");
 scanf("%d",&i);
 for(a=1;a<=i;a++){
                  printf("%d + ",fibo(a));  
                  }
 printf("\b\b  ");
 printf("\n");
 system("PAUSE");
 return 0;
}

int fibo(int data)
{
 if(data==1 || data==2){            // 초기 값은 정해놓고 시작 
                        return 1;
                        }
else{
 return fibo(data-1)+fibo(data-2); // n번째 수가 나오려면 n-1 과  n-2 를 더하면 나옴.
}
}

*/

Posted by 샤키
C/C++2009. 3. 19. 23:23

#include <stdio.h>
#include <stdlib.h>
#include <time.h>


#define Bet 100;

int main(){

 int Player1,Player2,Player3;
 int Com1,Com2,Com3;
 int Player,Com;
 int Money=1000;
 int Count1,Count2,Count3;
 int Count4,Count5;
 int Select;
 char ch;
 int Betting;
 char Card;

 srand(time(NULL));
 rand();rand();rand();
 srand(rand());
 Count1 = Count2 = Count3 = 0;
 Count4 = Count5 = 0;


 while(1){
  system("cls");
  printf(" ==== 블랙잭 ====\n");
  printf(" 1. 게임시작 \n");
  printf(" 2. 점수\n");
  printf(" 3. 게임 끝\n");
  printf(" > ");
  scanf("%d",&Select);
  system("cls");
  switch(Select){
    case 1:

     Money = Money - Bet;
     Betting = 0;     
     Player1 = rand()%13+1;
     Player2 = rand()%13+1;
     printf("=================\n");
     printf("||      %d      ||\n",Player1);
     printf("=================\n");
     printf("=================\n");
     printf("||      %d      ||\n",Player2);
     printf("=================\n");


     printf("당신의 카드의 합 : %d\n",Player1+Player2);
     printf("\n");


     Com1 = rand()%13+1;
     Com2 = rand()%13+1;
     printf("=================\n");
     printf("||      %d      ||\n",Com1);
     printf("=================\n");
     printf("=================\n");
     printf("||      %d      ||\n",Com2);
     printf("=================\n");


     printf("컴퓨터의 카드의 합 : %d\n",Com1+Com2);

     while(1){
      printf("카드를 하나 더 받겠습니까? (y/n) :");
      fflush(stdin);
      scanf("%c",&Card);
      if(Card=='Y' || Card == 'y'){       
       Player3 = rand()%13+1;      
       printf("=================\n");
       printf("||      %d      ||\n",Player3);
       printf("=================\n");
       Count4++;
      }else if(Card=='N' || Card == 'n'){
       Player3 = 0;
       break;
      }else{
       printf("잘못 입력하셨습니다 \n");
       system("pause");
       
      }
     
     Player = Player1+Player2+Player3;     
     printf("\n");
     printf("당신 카드의 총합 : %d \n",Player);
     }
     system("pause");
     
     
     while(1){
      if((Com1+Com2)<16){       
       printf("\n");
       printf("컴퓨터가 카드를 한장 더 받았습니다.\n");
       printf("\n");
       Com3 = rand()%13+1; 
       Count5++;
      }else if(16 <= (Com1+Com2) && (Com1+Com2) <=21){
       Com3 = 0;       
       break;
      }
     }
      Com = Com1+Com2+Com3;      
  

      printf("배팅을 하시겠습니까? (y/n) : ");
      fflush(stdin);
      scanf("%c",&ch);
      if(ch=='Y' || ch == 'y'){

       printf("배팅금액 설정 ( 0 ~ %d ) : ",Money);
       scanf("%d",&Betting);     
      }
      printf("컴퓨터의 카드의 합 : %d\n",Com);
    switch(ch){
    case 'y':     //배팅을 걸때 상황
     if((Player<=21||Com<Player)||Count4<Count5){
      printf("당신이 이겼습니다.\n");
      Money = Money + (Betting*2) + Bet;
      Count1++;
     }else if((Player>21&&Com>Player)||Count4>Count5){
      printf("당신이 졌습니다.\n");
      Money = Money - Betting;
      Count2++;
     }else{
      printf("비겼습니다.\n");
      Money = Money + Bet;
      Count3++;
     }break;

    case 'n':     //배팅을 안걸때 상황
     if((Player<=21||Com<Player)||Count4<Count5){
      printf("당신이 이겼습니다.\n");
      Money = Money + Bet;
      Count1++;
     }else if((Player>21&&Com>Player)||Count4>Count5){
      printf("당신이 졌습니다.\n");
      Count2++;
     }else{
      printf("비겼습니다.\n");
      Money = Money + Bet;
      Count3++;
     }break;
    }
      break;

    case 2:       //스코어
     printf("<< 당신의 전적 >>\n");
     printf(" W  I  N : %d\n",Count1);
     printf(" L O S E : %d\n",Count2);
     printf(" D R A W : %d\n",Count3);
     printf("보유하고 있는 금액 : %d\n",Money);
     break;
    case 3:
     return 0;

    default :
     printf("잘못 누르셨습니다 1~3중만 고르세요\n");
     }
     system("pause");
  }

 
}


미완성본 에러가 계속 나는데 왜 그런지 모르겠다 ㅜㅜ

Posted by 샤키
C/C++2009. 3. 19. 23:20
#include <Stdio.h>
#include <stdlib.h>
#include <time.h>

int main(){
int Com,Player;
int Count=0;
int i;
srand(time(NULL));
rand();rand();rand();

printf("== Game Start ==\n");

while(1){
printf("Input Number(1~3) : ");
scanf("%d",&Player);
if( !(1 <= Player && Player <=3 ) ){
printf("범위가 잘못되었습니다. \n");
continue;
}

for(i=0;i<Player;i++){
printf("Count = %d \n",++Count);
if(Count==31){
printf("You Lose !! \n");
return 0;
}
}
printf("== Computer Turn ==\n");

if(Count==29){
Com = 1;
}else if(Count==28){
Com = 2;
}else if(Count==27){
Com = 3;
}else{
Com = rand()%3+1;
}
for(i=0;i<Com;i++){
printf("Count = %d \n",++Count);
if(Count==31){
printf("You Win !! \n");
return 0;
}
}
}
return 0;
}


쌤 ver. 이다
난 왜 안만들었는지..!?


Posted by 샤키
C/C++2009. 3. 19. 00:29

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void){

 int i;        //for문
 int sel;
 int P_dic,C_dic;    //주사위값
 int sum1,sum2;     //주사위합
 int count1,count2,count3;  // 스코어
 int P_mon;      //내돈
 int Pan;      //판돈
 int Bet;      //배팅 금액
 char sel1;

 srand(time(NULL));
 rand();rand();rand();
 srand(rand());


 count1 = count2 = count3 = 0; //초기값 어렵다
 P_mon = 1000;     //처음 보유금액
 Pan = 10;      //판돈 10으로 설정

 while(1){

  system("cls");
  printf("== Dice Game==\n");
  printf("1. Game Start\n");
  printf("2. Game Score\n");
  printf("3. End Game\n");
  printf(">");
  scanf("%d",&sel);


  switch(sel){

   case 1:
    if(P_mon <= 0){      //보유돈이 0이 되었을때 게임시작하면 나오는 멘트
     printf("돈이 없으면 꺼져주세요\n");
     return 0;
    }
    sum1 = sum2 = 0;  //초기값 이것때문 엄청 고생
    Bet = 0;
    P_mon = P_mon - Pan; //판돈 지불

    system("cls");
    printf("보유 금액:%d\n",P_mon);
    printf("<< 주사위 게임 >>\n");
    for(i=0;i<3;i++)
    {
     P_dic = rand()%6+1;
     sum1 = sum1 + P_dic;

    }
    printf("당신의 주사위의 합 : %d\n",sum1);
    printf("배팅을 하겠습니다(y/n): ");
    fflush(stdin);   //버퍼 비우고
    scanf("%c",&sel1);

 

 


    for(i=0;i<3;i++)
    {
     C_dic = rand()%6+1;
     sum2 = sum2 + C_dic;

    }

    switch(sel1){
   case 'y':     //배팅을 걸때 상황
    printf("배팅 금액은? (1 ~ %d) : ",P_mon);
    scanf("%d",&Bet);
    system("cls");
    printf("주사위 값입니다\n");
    printf("컴퓨터의 주사위의 합 : %d\n",sum2);

    if(sum1>sum2){
     printf("당신이 이겼습니다.\n");
     P_mon = P_mon + Pan + (Bet*2);
     count1++;
    }
    else if(sum1<sum2){
     printf("당신이 졌습니다.\n");
     P_mon = P_mon - Bet;
     count2++;
    }
    else{
     printf("비겼습니다.\n");
     P_mon = P_mon + Pan;
     count3++;
    }break;


   case 'n':     //배팅을 안걸때 상황
    system("cls");
    printf("주사위 값입니다\n");
    printf("컴퓨터의 주사위의 합 : %d\n",sum2);

    if(sum1>sum2){
     printf("당신이 이겼습니다.\n");
     P_mon = P_mon + Pan;
     count1++;
    }
    else if(sum1<sum2){
     printf("당신이 졌습니다.\n");
     count2++;
    }
    else{
     printf("비겼습니다.\n");
     count3++;
    }break;
    }


    break;


   case 2:       //스코어
    printf("<< 당신의 전적 >>\n");
    printf(" W  I  N : %d\n",count1);
    printf(" L O S E : %d\n",count2);
    printf(" D R A W : %d\n",count3);
    printf("보유하고 있는 금액 : %d\n",P_mon);
    break;


   case 3:       //게임 끝내는거
    return 0;

   default :      //잘못 눌렀을때
    printf("잘못 누르셨습니다 1~3중만 고르세요\n");
  }
  system("pause");
 }

}





오늘은 여기까지 밀린거 다 포스팅 했다
낼은 나머지 포스팅 하고..

그리고 밀린 블랙잭도 얼렁 해야 하는데 ㅜㅜ

Posted by 샤키
C/C++2009. 3. 19. 00:26

/*
#include <Stdio.h>
#include <stdlib.h>
#include <time.h>


int main(){


 int Select;
 int Com,Player;
 int Count;
 int Min=99;
 int flag;


 srand(time(NULL));
 rand();rand();rand();


 while(1){


  system("cls");


  printf("== UP & Down Game ==\n");
  printf(" 1. Game Start \n");
  printf(" 2. Game Score \n");
  printf(" 3. End Game \n");
  printf(" > ");
  scanf("%d",&Select);
  switch(Select){
   case 1:


    // 초 기 값


    Count = 0;
    Com = rand()%99+1;
    flag = 0;


    // 루 프 문


    while(1){


     //출력
     if(flag == 0){
      printf("<< Game Start >>\n");
     }else if(flag ==1){
      printf("<< U        P >>\n");


     }else if(flag ==2){
      printf("<< D  O  W  N >>\n");
     }else if(flag ==3){
      printf("<< 정답을 맞췄습니다!! >>\n");
      printf("%d 만에 정답을 맞추셨습니다 \n",Count);


     
      if(Min > Count){
       Min = Count;
       printf(" 와우~~~!! \n");
       printf("최고점수가 갱신되었습니다 \n");


      }
     
      break;
     }


     //입력
     printf("%dth Input Number : ",++Count);
     scanf("%d",&Player);
     
     //연산


     if(Player > Com ){
      flag = 2;
     }else if(Player < Com ){
      flag = 1;
     }else{
      flag = 3;
     }

 


    }   

 


    break;
   case 2:


    if(Min==99){
     printf("아직 게임을 시작하지 않았습니다 \n");
     break;
    }


    printf("당신의 최고 점수는 %d 입니다 \n",Min);
    break;
   case 3:
    printf("게임을 종료하겠습니다. \n");
    return 0;
  }
  system("pause");
 }

*/



Posted by 샤키