Selection Exercise 2
Develop a program to process a set of account transactions. All positive amounts should be accumulated as credits. All negative amounts should be accumulated as debits. The total credits and debits for the period should be displayed. The program should ask the user if there is more input and terminate when the user responds with 'n' or 'N'.
Algorithm
AccountTransactions
credits:= 0
debits:= 0
display opening menu {LS1}
read user response {validate for
'c', 'C','n','N'}
while user response <> 'N' do
display input screen {LS2}
read
amount
if amount >= 0 then
write
amount
credits:=
credits + amount
write
credit
else {amount
must be negative}
write
amount
debits:=
debits + amount
write
debits
endif
display another input prompt
read response {validate
for 'a', 'A','n','N'}
endwhile
End.
Data
Item Table
Data Item | Program name | Size/Type | Range |
Credits | credits | float | |
Debits | debits | float | |
Amount | amount | float | |
User response | response | char | 'n' or 'N' |
PROGRAM: account.cpp