0% found this document useful (0 votes)
15 views8 pages

Assigment1 Answer

This document contains an algorithm that allows a user to purchase items from a store and calculates the total cost. It includes variables to track the quantity and prices of milk, bread, eggs, and toilet paper purchased. Conditionals are used to calculate prices based on item quantities and apply discounts. The total cost is displayed at the end.

Uploaded by

hudasalhadin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

Assigment1 Answer

This document contains an algorithm that allows a user to purchase items from a store and calculates the total cost. It includes variables to track the quantity and prices of milk, bread, eggs, and toilet paper purchased. Conditionals are used to calculate prices based on item quantities and apply discounts. The total cost is displayed at the end.

Uploaded by

hudasalhadin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

HiLCoE

School of Computer Science


and Technology

Department of software enginnering

Course CS221

Assigment 1

Done by huda salhadin

Submission date november 28 2022


This is an algorithm that allows a user to purchase an item they want and display
the total amount

Written by huda salhadin

Written date november 26 2022

START

LET Items is the character representing the type of items in the mart

LET gallon is an integer representing the amount of milk

LET price of milk is a real number representing the total price of milk purchased

LET Loaf is an integer representing the amount of bread

LET couponCode is a character representing the coupon code for bread that is R
or N

LET price of bread is a real number representing the total price of breads
purchased

LET HalfDozen is an integer representing the half dozens of eggs

LET FullDozen is an integer representing the full dozens of eggs

LET price of egg for FullDozen is a float representing the price full dozens of eggs
purchased

LETprice of HalfDozen is a rational number representing the price half dozens of


eggs purchased

LET Total price egg is a rational number representing the total price of half dozen
and full dozeneggs

LET Discount is the real number representing the discount given for the eggs

LET number of ToiletPaper is the integer representing the amount of toilet paper
LET ToiletPaper price is a real number representing the total price of toilet paper
purchased

LET ToiletPaper tracker is a real number that stores the number of toilet papers
purchashed

LET price of toilet paper on extra credit is a real number represnting the price of
toilet paper with extra credit

LET Total is the sum of all the items purchased

DISPLAY "this is huda mart"

DO //this is the loop used to repeat the menu until the user selects to exit

DISPLAY"what do you want to buy"

DISPLAY "our menu"

DISPLAY "1 milk"

DISPLAY "2 bread"

DISPLAY "3 egg"

DISPLAY "4 toilet"

DISPLAY "5 paper"

WHILE item != 5

GET item

WHILE item !=1 OR 2 OR 3 OR 4 OR 5

DISPLAY"we don't sell item, please make another selection"

GET item

END WHILE

IF item=1 THEN// this if statment calculates the price of milk based on conditions
DISPLAY"please enter the amount of gallons you want"

GET gallon

WHILE gallon <= 0

DISPLAY" error! Gallons should be entered in natural numbers"

DISPLAY"please enter the amount of gallons"

GET gallon

END WHILE

Price of milk=gallon*6.25

ELSE IF item=2 THEN //this if statment calculates the price of bread based on the
given conditions

DISPLAY"please enter the amount of loafs you want"

GET loaf

WHILE loaf <= 0

DISPLAY"error! Loafs should be entered in natural numbers"

DISPLAY"please enter the amount loafs"

GET loaf

END WHILE

DISPLAY "please enter your coupon code"

DO

coupon code==N THEN

Price of bread=loaf*2.25

ELSE IF coupon code==R THEN


Price of bread=loaf*1.50

END IF

ELSE IF item==3 THEN //this if statment calculates the price of egg based on the
given conditions

DISPLAY"please select the dozens you want"

DISPLAY"1 full dozen"

DISPLAY"2 full dozen"

DO

GET dozen

WHILE dozen !=1 or 2

DISPLAY"please select the amount of dozen correctly"

GET dozen

IF dozen==1 THEN

DISPLAY"please enter how many full dozens you want"

GET number of full dozens

WHILE number of full dozens<=0

DISPLAY "error! Dozens should be entered in natural number"

DISPLAY "please enter the amount of dozens"

GET number of full dozens

END IF

Price of egg full dozen=3.5* number of full dozens

IF dozen==2 THEN
DISPLAY"please enter how many half dozens you want"

GET number of half dozens

WHILE number of half dozens<=0

DISPLAY "error! Dozens should be enteres in natural numbers"

DISPLAY "please enter the amount of dozens"

GET number of half dozens

END WHILE

Price of egg half dozen=2 * number of half dozens

Total price egg=price of full dozen*price of half dozen

END IF

ELSE IF item==4 THEN //this if statment calculates the price of toilet paper based
on the given conditions

DISPLAY "please enter the number of toilet paper you want"

DO

GET number of toilet paper

WHILE number of toilet paper<=0 THEN

DISPLAY "error!number of toilet paper should be entered in natural numbers"

DISPLAY"please enter the amount of toilet papers"

GET number of toilet paper

IF number of toilet paper<=5 or >=1 THEN

Price of toilet paper=number of toilet paper*1.99

IF number of toilet paper<=10 or >=6 THEN


Price of toilet paper=number of toilet paper*1.49

IF number of toilet paper >=11 THEN

Price of toilet paper=number of toilet paper * 0.99

END IF

// this stores the amount of toilet paper entered and adds the new amount of
toilet paper entered to keep the number of oilet paper sold in track

Toilet paper tracker=number of toilet paper + toilet paper tracker

IF number of toilet paper tracker<=5 or >=1 THEN

Price of toilet paper on extra credit=toilet paper tracker *1.99

IF number of toilet paper trakcker<=10 or >=6 THEN

Price of toilet paper on extra credit =toilet paper tracker * 1.49

IF number of toilet paper tracker >=11 THEN

Price of toilet paper on extra credit =toilet paper tracker * 0.99

END IF

Total=price of milk+price of bread+price of egg+price of toilet paper

ElSE IF item==5 THEN//all the total price is displayed after we are out of the loop

DISPLAY"price of milk"price of milk

DISPLAY"Price of bread"price of bread

DISPLAY"price of egg"price of egg

DISPLAY"price of toilet paper"price of toilet paper

DISPLAY"discount for egg"discount


DISPLAY"price of toilet paper on exrra credit"price of toilet paper on extra
credit

DISPLAY"total price"total

STOP

You might also like