다음의 문제를 가지고 소스를 제작했지만 계속 에러가 나는 군요.
문제)
제작자를 나타내는 문자배열로 된 문자열, 제작 연도를 나타내는 정수를 자동차에
관련된 정보로써 저장하고 있는 car라는 구조체를 설계하고, 몇 대의 차를 목록으로
만들 것인지를 사용자에게 묻는 프로그램을 작성하라. 요구하는 만큼의 car 구조체의
동적인 배열을 만들기 위해서 new를 사용해야 하며 그러고 나서, 각 구조체에 넣을
제작자와 제작연도 정보를 입력하도록 사용자에게 요구하는 프롬프트를 제시해야
한다. 이것은 수치데이터와 문자열을 번갈아 읽어들여야 하기 때문에 약간의 주의가
필요하다. 끝으로, 각 구조체의 내용을 출력해야 한다.
실행 예)
How many cars do you wish to catalog? 2
Car #1:
Please enter the make: Hudson Hornet
Please enter the year made: 1952
Car #2:
Please enter the make: Kaiser
Please enter the year made: 1951
Here is your collection:
1952 Hudson Hornet
1951 Kaiser
내가 만든 잘못된 소스)
#include<iostream.h>
struct car
{
char maker[20];
int year_made;
};
int main(void)
{
//catolog는 차종의 수, num은 차종의 수에 따른 배열
int catalog, num;
cout<<"How many cars do you wish to catalog? ";
cin>>catalog;
//배열로 이루어진 동적 구조체변수 할당
car *CarKind=new car [catalog];
for(num=0;num<catalog;++num){
cout<<"\n\ncar #"<<num<<":\n\n";
cout<<"Please enter the maker: ";
cin.getline(CarKind[num] -> maker,20);
cout<<"\n\nPlease enter the year made: ";
cin>>CarKind[num] -> year_made;
}
cout<<"\n\nHere is your collection:";
for(num=0;num<catalog;++num)
cout<<"\n\n"<<CarKind[num] -> year_made<<" "<<CarKind[num] -> maker;
delete [] CarKind;
return 0;
}
==================해결 부탁합니다.============================================
긴 답변이 필요하시면 hwansos@chollian.net으로 메일을 이용해 보내주시면
감사하겠습니다.
==============================================================================
|