2017-10-05 43 views
0

我想要顯示所有在特定日期內購買項目的客戶,這是通過使用客戶數組與if/else語句或使用當天的枚舉來完成的嗎?任何幫助或例子都會很棒,謝謝!Pascal - 我如何根據一個條件返回值?

type 
day = (monday, tuesday); 

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

TCustomers = array of Tcustomer; 

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

    selection := ReadIntegerRange('Select day purcased (1 - 3): ', 1, 
    3); 
    result := day(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 
     result[i].name := ReadString('Customer name: '); 
     result[i].itemPurchased := ReadString('Item Purchased: '); 
     result[i].dayPurchased := readDay(prompt); 
    end; 
end; 
+0

* ...使用customers數組與if/else stat或者使用當天的枚舉*。我猜答案是兩個?不知道爲什麼你認爲這些是彼此的替代品。您必須檢查每個客戶條目以獲取所需的枚舉值。 – lurker

回答

1

你必須:

定義Customers變量
得到客戶的數組它
創建specific_day參數
此過程中的程序進行循環,並檢查與if-運算符比較所有數組元素dayPurchased字段與specific_day

相關問題