How do i display all customers who have purchased an item on a certain day, my code doesn't seem to work, ive tried implementing the code within the displayByDayPurchased procedure. Sorry if this is a simple question, i'm still new to programming.
Tday = (monday, tuesday);
Tcustomer = record
Tcustomers = array of Tcustomer;
function readDay(prompt:string): Tday;
selection := ReadIntegerRange('Select day purcased (1 - 3): ', 1, 3);
result := Tday(selection-1);
numOfCustomers := ReadInteger('Enter number of customers: ');
for i := 0 to high(result) do
result[i].itemPurchased := ReadString('Item Purchased: ');
result[i].dayPurchased := readDay(prompt);
specific_day := ReadInteger('Enter day to see items purchased');
if (specific_day = customers.dayPurchased[specific_day])then
customer := readCustomers('Read in customers');
my code doesn't seem to work, ive tried implementing the code within the displayByDayPurchased procedure.
Well, in the code you've posted, your
displayByDayPurchased doesn't actually implement anything which would result in matching records being displayed, all you have is an empty
begin ... end block:
if (specific_day = customers.dayPurchased[specific_day])then begin end;
and a) that doesn't correctly specify the match condition anyway and b) it will not compile because a
Tcustomers array does not have a
dayPurchased field ( a
Tcustomer record does, but not the array).
Your code depends of quite a lot of things whose definitions you have not provide (
ReadIntegerRange, etc) so it is difficult to give you a tested solution.
However an implementation of your
displayByDayPurchased should probably look something like this:
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;
I assume your
Tcustomer record actually includes the customer's name, andx your code needs modifying to handle that.
function readDay(prompt:string): Tday is wrong; Because of your definition of
Tday, the allowed values in
readDay should be 0 and 1, because the lowest value of the
Tday enumeration actually corresponds to zero, not 1.
Also, you did not say which Pascal compiler you are using, but most modern versions allow a call like
Tday(integerValue) to convert an integer to an instance value of the enumeration.