I have to create a program that would take bus tickets and I've done alright up to this point but my main problem now is the ticket procedure. I want it to show the results of a ticket i.e for a childs ticket or adults ticket. Does anyone have any suggestions?Code:program bus; uses wincrt; Var parray:array [1..9] of real; countperson,thedate,startingpoint,endpoint,selection, tickettotal:integer; Number,cashgiven,recieved:real; quit:boolean; Returntrip:char; Tickettype:string; Procedure pause; begin Writeln; Writeln; Writeln('Please press enter to continue'); Readln; End; Procedure child; begin Number:= 0; clrscr; parray[1] := 0.70; parray[2] := 0.80; parray[3] := 0.75; parray[4] := 1.10; parray[5] := 0.75; parray[6] := 1.40; parray[7] := 1.55; parray[8] := 0.50; parray[9] := 0.00; Writeln('Please enter your start point '); readln(startingpoint); Writeln('Please enter your stopping point '); readln(endpoint); Writeln; Writeln('Would you like a return: y/n'); readln(Returntrip); Writeln('Cash given:'); readln(cashgiven); If (Returntrip = 'y') or (Returntrip = 'Y') then Begin For tickettotal := startingpoint to (endpoint-1) DO begin Number := Number + parray[tickettotal]*1.50; recieved := cashgiven - Number; countperson := countperson + 1; end; End else Begin For tickettotal :=Startingpoint to (endpoint-1) DO begin Number := Number + parray[tickettotal]; recieved := cashgiven - Number; countperson := countperson + 1; end End; Writeln('The total trip will cost ',Number:6:2); Writeln('Your change is ',recieved:6:2); Writeln('Number of passengers ',countperson); pause; End; Procedure adult; begin Number:= 0; clrscr; parray[1] := 1.00; parray[2] := 1.20; parray[3] := 1.05; parray[4] := 1.56; parray[5] := 1.05; parray[6] := 1.90; parray[7] := 2.10; parray[8] := 0.80; parray[9] := 0.00; Writeln('Please enter your start point '); readln(startingpoint); Writeln('Please enter your stopping point '); readln(endpoint); Writeln; Writeln('Would you like a return: y/n'); readln(Returntrip); Writeln('Cash given:'); readln(cashgiven); If (Returntrip = 'y') or (Returntrip = 'Y') then Begin For tickettotal :=Startingpoint to (endpoint-1) DO begin Number := Number + parray[tickettotal]*1.60; recieved := cashgiven - Number; countperson := countperson + 1; end; End else Begin For tickettotal :=Startingpoint to (endpoint-1) DO begin Number := Number + parray[tickettotal]; recieved := cashgiven - Number; countperson := countperson + 1; end End; Writeln('The total trip will cost ',Number:6:2); Writeln('Your change is ',recieved:6:2); Writeln('Number of passengers ',countperson); pause; End; Procedure OAP; begin Number:= 0; clrscr; parray[1] := 0.75; parray[2] := 0.85; parray[3] := 0.80; parray[4] := 1.20; parray[5] := 0.80; parray[6] := 1.55; parray[7] := 1.75; parray[8] := 0.65; parray[9] := 0.00; Writeln('Please enter your start point '); readln(startingpoint); Writeln('Please enter your stopping point '); readln(endpoint); Writeln('Would you like a return ticket: y/n'); readln(Returntrip); Writeln('Cash given:'); readln(cashgiven); If (Returntrip = 'y') or (Returntrip = 'Y') then Begin For tickettotal :=Startingpoint to (endpoint-1) DO begin Number := Number + parray[tickettotal]*1.55; recieved := cashgiven - Number; end; End else Begin For tickettotal :=Startingpoint to (endpoint-1) DO begin Number := Number + parray[tickettotal]; recieved := cashgiven - Number; end End; Writeln('The total trip will cost ',Number:6:2); Writeln('Your change is ',recieved:6:2); pause; End; Procedure Ticket; begin clrscr; Writeln('==============================================================='); Writeln('==============================================================='); {Writeln('Travel this way busses Date ');} Writeln; Writeln('= '); Writeln('Ticket number: ',countperson,' Boarded stop: ',startingpoint); Writeln; Writeln('= Alighted stop : ',endpoint); Writeln; {Writeln('= Type : ',ticketype);} Writeln; Writeln('= Price : ',Number); end; Procedure menu; begin clrscr; quit :=false; repeat; Writeln('------------------------------------------'); Writeln('------------------------------------------'); Writeln('1.adult'); Writeln; Writeln('2.child'); Writeln; Writeln('3.OAP'); Writeln; Writeln('4.quit'); Writeln; Writeln('5.Ticket'); Writeln('-------------------------------------------'); Writeln('-------------------------------------------'); writeln; writeln('Please make your selection '); readln(selection); case selection of 1: adult; 2: child; 3: OAP; 4: quit :=true; 5: Ticket; end; clrscr; until quit; end; {main program} begin menu; end.
Last edited by WingedPanther; 01-30-2009 at 10:44 AM. Reason: add code tags (the # button)
You can handle the output within the adult/child function, or you can change the procedure to a function that hands output back to the ticket function.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks