2017-10-22 2 views
1

특정 날짜에 항목을 구입 한 모든 고객을 표시하고 코드가 작동하지 않는 것처럼 보이게하려면 displayByDayPurchased 프로 시저 내에서 코드를 구현해야합니다. 죄송합니다. 간단한 질문이라면 프로그래밍을 처음 접해 보겠습니다.레코드가 작동하지 않는 조건문

type 

Tday = (monday, tuesday); 

    Tcustomer = record 
     itemPurchased:string; 
     dayPurchased: Tday; 
    end; 

    Tcustomers = array of Tcustomer; 

function readDay(prompt:string): Tday; 
var 
    selection:Integer; 
begin 
    writeln('1. Monday'); 
    writeln('2. Tuesday'); 

    selection := ReadIntegerRange('Select day purcased (1 - 3): ', 1, 3); 
    result := Tday(selection-1); 
end; 

function readCustomers(prompt:string):TCustomers; 
var 
    numOfCustomers:integer; 
    i:integer; 
begin 
    numOfCustomers := ReadInteger('Enter number of customers: '); 
    setLength(result, numOfCustomers); 

    for i := 0 to high(result) do 
    begin 
     writeln(i); 
     result[i].itemPurchased := ReadString('Item Purchased: '); 
     result[i].dayPurchased := readDay(prompt); 
    end; 
end; 

procedure displayByDayPurchased(customers:TCustomers); 
var 
    specific_day:integer; 
begin 
    specific_day := ReadInteger('Enter day to see items purchased'); 

    if (specific_day = customers.dayPurchased[specific_day])then 
    begin 

    end; 
end; 

procedure Main(); 
var 
    customer: Tcustomers; 
begin 
    customer := readCustomers('Read in customers'); 

end; 

begin 
    Main(); 
end. 

답변

2

내 코드는 필자가 displayByDayPurchased 절차 내에서 코드를 실행하려고 작동하지 않습니다.

음, 코드에서 당신이 게시 한, 당신의 displayByDayPurchased 실제로 일치하는 레코드를 초래 아무것도, 당신이 가진 모든 빈 begin ... end 블록 표시되고 구현하지 않습니다

if (specific_day = customers.dayPurchased[specific_day])then 
begin 

end; 

및 a) 어쨌든 일치 조건을 정확하게 지정하지 않고 b) Tcustomers 배열에 dayPurchased 필드가 없으므로 컴파일되지 않습니다 (Tcustomer 레코드는 있지만 배열은 아닙니다).

귀하의 코드는 (ReadString, ReadInteger, ReadIntegerRange 등) 제공하지 않은 많은 것들에 따라 달라 지므로 테스트를 거친 솔루션을 제공하기가 어렵습니다.

그러나 당신의 displayByDayPurchased의 구현은 아마 다음과 비슷한 모습이 될 것입니다
procedure displayByDayPurchased(customers:TCustomers); 
var 
    specific_day:integer; 
    i : integer; 
    ADay : Tday; 
begin 
    specific_day := ReadInteger('Enter day to see items purchased'); 
    ADay := Tday(specific_day); // converts integer to TDay value 

    for i := Low(customers) to High(Customers) do begin 
     if customers[i].dayPurchased = ADay then begin 
     writenln(customers[i].itemPurchased); 
     end; 
    end; 
end; 

내가 당신 Tcustomer 기록이 실제로 고객의 이름이 포함 된 가정 andx 코드가 그것을 처리하기 위해 수정해야합니다.

Btw, function readDay(prompt:string): Tday입니다.입니다. Tday 열거의 가장 낮은 값이 실제로 또한하지, 제로로 1

에 해당하기 때문에 때문에 Tday의 당신의 정의의, readDay에서 허용되는 값은 당신이 사용하고있는 파스칼 컴파일러 말하지 않았다, 0과 1이어야한다 하지만 대부분의 최신 버전에서는 Tday(integerValue)과 같은 호출을 사용하여 정수를 인스턴스 열거 형 값으로 변환 할 수 있습니다.