PRINT MONEY AMOUNTS
Algorithm
Main
Program
Initialize
any necessary values
GET
User Input // dollars and cents
LOOP
WHILE NOT $0.0
IF dollars > 999
thousands = dollars / 1000
CALL Print_3digitnum ( thousands )
Print "Thousand"
END IF
IF dollars > 0
CALL Print_3digitnum ( dollars % 1000 )
Print "and cents/100 Dollars"
ELSE
Print "Zero and cents/100 Dollars"
END IF
GET User Input // next numbers
END
LOOP
Print_3digitnum
Header:
void
Print_3digitnum( /* in */ int Num2Print )
PreCondition: Num2Print is assigned &&
1 <= Num2Print <= 999
PostCondition:
Word
equivalent of
Num2Print has been printed
IF
Num2Print > 99
CALL Print_digit ( Num2Print / 100 )
Print "Hundred"
END
IF
CALL
Print_2digitnum ( Num2Print % 100 )
Print_2digitnum
Header:
void
Print_2digitnum( /* in */ int Num2Print )
PreCondition: Num2Print is assigned &&
1 <= Num2Print <= 99
PostCondition:
Word
equivalent of
Num2Print has been printed
TensDigit
= Num2Print / 10
OnesDigit
= Num2Print % 10
IF
TensDigit == 0 AND OnesDigit > 0
CALL Print_digit ( OnesDigit )
ELSE
IF TensDigit == 1
IF OnesDigit == 0 Print Ten
ELSEIF OnesDigit == 1 Print Eleven
etc...
ELSE
// TensDigit must be 2 or more
IF TensDigit == 2 Print Twenty
ELSEIF TensDIgit == 3 Print Thirty
etc...
IF Onesdigit > 0
CALL Print_digit ( OnesDigit )
END IF
END
IF
Print_digit
Header:
void
Print_digit( /* in */ int Num2Print )
PreCondition: Num2Print is assigned &&
0 <= Num2Print <= 9
PostCondition:
Word
equivalent of
Num2Print has been printed
IF
Num2Print == 1 Print "One"
ELSE
IF Num2Print == 2 Print "Two"
etc.