CSCI 150, Spring 2003

Home | | Course Schedule | | Assignments | | Lecture Notes

Homework 4 solution

{Author: Brenda Student
Section: CSCI 150, Section 1
Date:   2/28/03
Assignment: Homework 4
Purpose: Print out items whose prices are less than an amount
		entered by the user.}

program price;
type
	realArray15 = array[1 .. 15] of real;
	stringArray15 = array[1 .. 15] of string;
var
	item : realArray15;			{List of items for sale}
	price : stringArray15;		{Prices of items for sale}
	searchPrice : real;			{Price entered by user}
	counter : integer;			{Loop counter}
begin
	item[1] := 'Toothpaste';
	price[1] := 2.75;
	item[2] := 'Batteries';
	price[2] := 7.25;
	item[3] := 'Picture Frame';
	price[3] := 8.37;
	item[4] := 'Hair brush';
	price[4] := 12.95;
	item[5] := 'Candy bar';
	price[5] := 0.75;
	item[6] := 'Gift Wrap';
	price[6] := 5.00;
	item[7] := 'Soap';
	price[7] := 1.15;
	item[8] := 'Video';
	price[8] := 14.95;
	item[9] := 'Shampoo';
	price[9] := 3.15;
	item[10] := 'Pencils';
	price[10] := 1.40;
	item[11] := 'Film Pack';
	price[11] := 6.10;
	item[12] := 'Vitamins';
	price[12] := 13.60;
	item[13] := 'Lollipop';
	price[13] := 0.50;
	item[14] := 'Glue Stick';
	price[14] := 1.35;
	item[15] := 'Calendar';
	price[15] := 3.75;

	writeln('How much would you like to spend?');
	readln(searchPrice);
	
	writeln('The following items can be bought for ', searchPrice:10:2, ':');
	for counter := 1 to 15 do
	begin
		if price[counter] <= searchPrice then
		begin
			writeln('Item: ', item[counter], '   Price: ', price[counter]:10:2);
		end;
	end;
end. {end of price program}