Enhance the pseudocode in the attachment by using arrays


Enhance the pseudocode in the attachment by using arrays and loops. Also, instead of hardcoding the product names within the program, ask the user to enter the product names in addition to the prices.

You can use char array products[5][40] and float array prices[5] to store the names and prices respectively (use "char products[6][40]" and "float prices[6]" if you want to simplify the code at the expense of a few more bytes of memory). Feel free to define additional arrays if needed.

main():

prompt the user to enter the price for apple
read apple_price

prompt the user to enter the price for banana
read banana_price

prompt the user to enter the price for grapes
read grapes_price

prompt the user to enter the price for pears
read pears_price

prompt the user to enter the price for tomato
read tomato_price

do
prompt whether the user wants to do checkout
read response
if response is yes then
invoke checkout()
endif
while response is yes;

print "Thanks for using checkout program".

checkout():

initialize total to 0

do

list the products
print 1. apples
print 2. banana
print 3. grapes
print 4. pears
print 5. tomatos

prompt the user to select a product or enter 0 for complete checkout
read selection

if selection > 0 then
prompt the user to enter weight
read weight

// you can alternatively use select ... case ... end structure when coding.

if selection is 1 then
add (weight * apple_price) to total
endif

if selection is 2 then
add (weight * banana_price) to total
endif

if selection is 3 then
add (weight * grapes_price) to total
endif

if selection is 4 then
add (weight * pears_price) to total
endif

if selection is 5 then
add (weight * tomato_price) to total
endif
endif
while selection is not 0;

if total > 50
apply 5% discount
output the discount and the new total
else
output total
endif

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Enhance the pseudocode in the attachment by using arrays
Reference No:- TGS01254921

Now Priced at $20 (50% Discount)

Recommended (99%)

Rated (4.3/5)