Download Problem: Create a receipt for a list of purchased items. Print the total

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Problem:
Create a receipt for a list of purchased items. Print
the total price, compute the total with 8.25% tax, and
print the money tendered (plus any change given)
• Input: a list of items and prices
• Output: a list of items and prices, plus the total,
total with tax, and cash tendered
Pseudocode:
1. Set the total to $0.00
2. For each item:
2.1. Print the item name and price
2.2. Add item price to total
3. Print total
4. Total with tax = 1.0825 * total
5. Print total with tax
6. Get cash tendered
7. Print cash tendered
8. If cash tendered > total with tax:
8.1. Change = cash tendered - total with tax
8.2. Print change
Flowchart
Start
total = 0
More item?
No
total_tax = 0.0825 * total
Yes
total = total + price
Item & price
total_tax
Get cash_tendered
cash_tendered
cash_tendered >
cash_tendered?
No
End
Yes
total_tax = 0.0825 * total
total_tax
Exercise:
Write a pseudo code and flow chart that reads 5
numbers between -100 and 100. Message “NOT
VALID” will be displayed if the number is not in the
range. The program calculates and displays
average of all 5 numbers.
Formula: Average = (num1+num2+…+num5)/5
Example:
Input
Output
102
NOT VALID
1, 20, 10, 4, -20 3
Pseudo code:
1. Start
2. COUNT = 0
3. TOTAL = 0
4. AVR = 0
5. If count < 5
5.1 Read NUMBER
5.2 If NUMBER >= -100 or NUMBER <=100
5.2.1 Display “NOT VALID”
5.2.2 Goto Step 5.1
5.3 TOTAL = TOTAL + NUMBER
5.4 COUNT = COUNT + 1
6. AVR = TOTAL / 5
7. Display Average
8. End
Flow chart:
Start
COUNT = 0
TOTAL = 0
AVR = 0
COUNT < 5?
Yes
Read NUMBER
Display NOT
VALID
No
NUMBER >= -100
&& NUMBER <= 100
Yes
TOTAL = TOTAL + NUMBER
COUNT = COUNT + 1
AVR = TOTAL/5
Display AVR
Start
No
Related documents