0% found this document useful (0 votes)
2 views

Algorithm Description

Uploaded by

grimesryke
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)
2 views

Algorithm Description

Uploaded by

grimesryke
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/ 4

Algorithm Description

Start Program:

Print welcome message: "Welcome to Davao Seoul Family Mart!"


Begin a loop to handle user role selection.
Role Selection Loop:

Prompt user to enter their role (Admin, Consumer, or exit).


Convert the input to lowercase and strip any extra whitespace.
Role Handling:

If Admin:
Call adminOptions().
If Consumer:
Call consumerOptions().
If exit:
Print a thank you message and exit the loop.
If invalid input:
Print an error message and prompt again.
Admin Options
Admin Options Loop:

Prompt admin to enter a choice (1 to add, 2 to remove, 3 to go back).


If 1:
Call addProduct().
If 2:
Call removeProduct().
If 3:
Return to main menu.
If invalid input:
Print an error message and prompt again.
Add Product:

Call getProductDetails() to collect product name, quantity, and price.


If valid details:
Call writeProductToFile() to save the product information to the file.
If invalid details:
Print an error message.
Remove Product:

Call getProductQuantityToRemove() to collect product name and quantity to


remove.
If valid details:
Call readProductsFromFile() to read current products.
Call writeUpdatedProductsToFile() to update the product list with the removed
quantity.
If invalid details:
Print an error message.
Consumer Options
Consumer Options Loop:

Initialize an empty basket.


Begin a loop to handle consumer choices.
Consumer Choices:

Try to read and display the product list from "Products.txt".


Display current basket contents and total cost.
Prompt consumer to enter a choice (1 to add to basket, 2 to remove, 3 to check out,
4 to go back).
If 1:
Call addToBasket() to add a product to the basket.
If 2:
Call removeFromBasket() to remove a product from the basket.
If 3:
Call checkout() to finalize the purchase and update the product file.
If 4:
Return to the main menu.
If invalid input:
Print an error message and prompt again.
Adding to Basket
Add to Basket:
Prompt user to enter product name and quantity.
Check product availability and add to basket if sufficient quantity exists.
If insufficient quantity:
Print an error message.
If product not found:
Print an error message.
Removing from Basket
Remove from Basket:
Prompt user to enter product name and quantity to remove.
If valid:
Adjust or remove the product from the basket.
If invalid:
Print an error message.
Checkout
Checkout:

Display basket contents and total cost.


Prompt user to enter the amount of money provided.
If sufficient funds:
Calculate change.
Update product quantities in the product file.
Clear the basket and print a success message.
If insufficient funds:
Print an error message.
End Program:

Exit the program upon user request.


This algorithm description provides a high-level overview of the program's logic and
flow, highlighting the main steps and decision points. If you need more detailed
explanations or specific parts of the code broken down further, let me know!

You might also like