c++에서 말이야

 

밑에 처럼 코드를 짜서 하면

구조체안에 있는 변수들이 죄다 깨지거든..

왜그럴까.. 어떤걸 잘못한걸까..





 

#include <iostream>
using namespace std;


struct CUSTOMER{
 char name[5];
 int age;
 char sex;


};

 

int main(){

 CUSTOMER customer[10];
 int num = 0;
 char menu;
 
 

 while(true){

  
  //메뉴출력
  cout <<"1. 고객 정보 입력" << endl;
  cout <<"2. 고객 정보 출력" << endl;
  cout <<"3. 종료" << endl;
  cout <<"메뉴 선택 : ";
  cin >>menu;

  if( menu == '3')
   break;

 


  switch(menu)
  {
  case '1':
   if(num==10)
   {
    cout << "더 이상 고객 정보를 입력 할 수 없습니다"<< endl;
    continue;
   }
   cout << "고객 이름 : ";
   cin >> customer[num].name;
   cout << "나이 : ";
   cin >> customer[num].age;
   cout << "성별(M, F) : ";
   cin >> customer[num].sex;

   num++;
   break;
  case '2':
   for(int i = 0 ; i < num ; i++){
    cout.width(20);
    cout.setf(ios_base::left);
    cout << customer[num].name;

    cout.width(3);
    cout << customer[num].age;
    cout << customer[num].sex << endl;

 

   }
   break;
  default :
   cout<<"잘못 입력하셨습니다." << endl;
   break;

  }
 }

 


 return 0;
}