Hi there!
This is a simple pascal program I wrote for a cashier. Please note that this is only a basic level program code and can't actually be used for commercial use.
Thanks for reading!
Hi there!
This is a simple pascal program I wrote for a cashier. Please note that this is only a basic level program code and can't actually be used for commercial use.
Thanks for reading!
Program Cashier(input,output);
Uses CRT;
Var i_count : integer;
i_price,total,dis,disa,distot,pay,payable,balance,paid : real;
disrate: string ;
Begin
writeln('WELCOME TO "PASCAL BASED E-SHOPPING"');
writeln(' ');
writeln('YOU WILL BE GIVEN A 5% DISCOUNT FOR SHOPPING MORE THAN RS.5000.00');
writeln('YOU WILL BE GIVEN A 10% DISCOUNT FOR SHOPPING MORE THAN RS.10000.00');
writeln('YOU WILL BE GIVEN A 15% DISCOUNT FOR SHOPPING MORE THAN RS.25000.00');
writeln('YOU WILL BE GIVEN A 20% DISCOUNT FOR SHOPPING MORE THAN RS.50000.00');
writeln(' ');
writeln('ENTER PRICES');
writeln(' ');
i_count:=1;
total:=0;
repeat
write(i_count,'. ');
read(i_price);
total:=total+i_price;
i_count:=i_count+1;
until i_price=0;
writeln(' ');
writeln('#################################################################');
writeln(' ');
writeln('THE TOTAL AMOUNT IS RS.',total:6:2);
writeln(' ');
if total>=50000 then
dis:=0.2
else
if total>=25000 then
dis:=0.15
else
if total>=10000 then
dis:=0.1
else
if total>=5000 then
dis:=0.05
else
dis:=0;
if dis=0.2 then
disrate:='20%'
else
if dis=0.15 then
disrate:='15%'
else
if dis=0.1 then
disrate:='10%'
else
if dis=0.05 then
disrate:='5%';
disa:=total*dis;
distot:=total-disa;
if dis<>0 then
writeln('YOU HAVE BEEN GIVEN A DISCOUNT OF RS.',disa:6:2,' AT THE RATE OF ',disrate)
else
writeln('SORRY, YOU HAVE NO DISCOUNT FOR YOUR SHOPPING.');
writeln(' ');
writeln('THE TOTAL AMOUNT PAYABLE IS RS.',distot:6:2);
writeln(' ');
writeln('#################################################################');
writeln(' ');
payable:=distot;
write('ENTER MONEY TO PAY: ');
readln(pay);
paid:=0;
paid:=paid+pay;
writeln(' ');
if paid>payable then
begin
balance:=paid-payable;
writeln('THANK YOU FOR YOUR PAYMENT. HERE, TAKE YOUR BALANCE : ',balance:6:2);
end;
if paid=payable then
begin
writeln('THANK YOU FOR YOUR PAYMENT.');
end;
if paid<payable then
begin
payable:=payable-paid;
repeat
write('ENTER ',payable:6:2,' RUPEES MORE : ');
readln(pay);
paid:=paid+pay;
payable:=payable-pay;
until distot<=paid;
if paid=distot then
begin
writeln(' ');
writeln('THANK YOU FOR YOUR PAYMENT.');
end;
if paid>distot then
begin
balance:=paid-distot;
writeln(' ');
writeln('THANK YOU FOR YOUR PAYMENT. HERE, TAKE YOUR BALANCE RS.',balance:6:2);
end;
end;
writeln(' ');
writeln('#################################################################');
writeln(' ');
writeln('THANK YOU FOR SHOPPING WITH US.');
writeln(' ');
writeln('........ COME AGAIN ........');
readkey();
End.
Not sure why there is any usage of Pascal as it is a dead language. Let's face it, the only reason it had such a large usage in the industry was because it was picked up by the colleges as a simple learning language for computer science. Then the college introductory teaching language moved on to Java, and now Python seems to be the most popular. What's next?
Why don't you use an array for the discount rates rather than a long series of if-then-else statements? It is very clumsy.
Pascal is an old programming language. I used it at University of Queensland in 1980s. It is not as powerful as others but it is elegant and easy to read compared to more cryptic languages like C or Perl.
distot:=total-disa;
could be written:
distot:=(1-dis)*total;
paid, payable and distot are confusing in last half. Why not use two of those variables?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.