#!/usr/bin/perl -w use strict ; my (@a, $userin, $userin2, $sum) ; @a = (1 .. 9) ; print "This program will ask you to type in two numbers and then add those numbers together.\nIt will then display the problem and the answer in word form.\n" ; $userin = 0 ; while ($userin ne "done") { print "Type in a single digit number between one and four, or type done to exit.\n" ; chomp ($userin = ) ; if ($userin eq "done") { last ; } print "Type in a single digit number between one and five\n" ; chomp ($userin2 = ) ; if (($userin =~ /^[^1-4]$/) || ($userin2 =~ /^[^1-5]$/)) { print "I do not understand\n" ; } else { $sum = ($userin + $userin2) ; $userin = ucfirst (numtoword($userin)) ; #was: $userin = (firstnumtoword($userin)) ; $userin2 = (numtoword($userin2)) ; $sum = (numtoword($sum)) ; print "$userin plus $userin2 equals $sum\n" ; } } sub numtoword { $_ = shift ; my (%nums) ; %nums = ("1"=>"one", "2"=>"two", "3"=>"three", "4"=>"four", "5"=>"five", "6"=>"six", "7"=>"seven", "8"=>"eight", "9"=>"nine") ; return $nums{$_} ; #was: return $nums{$userin2} ; } # sub firstnumtoword { # $_ = shift ; # my (%nums2) ; # %nums2 = ("1"=>"One", "2"=>"Two", "3"=>"Three", "4"=>"Four", "5"=>"Five", "6"=>"Six", "7"=>"Seven", "8"=>"Eight", "9"=>"Nine") ; # return $nums2{$userin2} ; # }