case 2 에서
for문 반복 안에 i로 변화를 주는데
구조체 배열의 인덱스로 i를 사용해야할 부분에 num이 들어가 있는 것과,
끝 부분에는 break를 붙이지 않아서 출력할 때
"잘못 입력하셨습니다."란 말이 나오게 되는 문제가 있네요.
오래된 자 님이 쓰신 글 :
: #include <iostream>
: using namespace std;
:
: struct CUSTOMER {
: char custoName[10]; // 고객 이름
: int age; // 나이
: char sex; // 성별
: };
:
: int main()
: {
: CUSTOMER customer[10];
: int num = 0;
: char menu;
:
: while (true)
: {
: // 메뉴 출력
: cout << "1. 고객 정보 입력\n";
: cout << "2. 고객 정보 출력\n";
: cout << "3. 종료\n";
: cout << "메뉴 선택 : ";
: cin >> menu;
:
: if (menu == '3')
: {
: cout << "종료합니다.";
: break;
: }
:
: switch (menu)
: {
: case '1':
: if (num == 10)
: {
: cout << "더 이상 고객 정보를 입력할 수 없습니다.\n";
: break;
: }
: cout << "고객 이름: ";
: cin >> customer[num].custoName;
: 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].custoName;
: cout.width(3);
: cout << customer[num].age;
: cout << customer[num].sex;
: }
: default:
: cout << "잘못 입력하셨습니다.\n";
: break;
: }
: }
: return 0;
: }
|