Computing.Net > Forums > Unix > need help on Unix program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

need help on Unix program

Reply to Message Icon

Name: mollyrb
Date: April 28, 2003 at 17:30:14 Pacific
OS: windows 98
CPU/Ram: I don't know
Comment:

Hey I'm doing a programmaning project in class. One of the programs I have to do is to create a program that will allow the user to type in a number, while the program outputs the number in words. Example, if you typed in 21, the computer would respond with twenty-one. Please allow the program to work for 0-50. If a number typed is not in that range, be sure to let the user know. I really need help with this program. How would I go about doing it? all the programs have to be in the bourne shell by the way. If you can help me please feel free to e-mail me at mollyrb_80@yahoo.com thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: April 28, 2003 at 23:26:02 Pacific
Reply:

Molly:

The easiest way of handling this is to use a tool that supports arrays such as awk or perl. Here's a stub that handles only 0 to 4 but you should be able to expand it and do some minor error checking:

#!/bin/sh


echo "Enter a number: \c"
read x

if [ $x -eq 0 ]
then
var="Zero"
else

var=`echo $x|awk ' BEGIN {
numbers[1]="one"
numbers[2]="two"
numbers[3]="three"
}
{
print numbers[$0]
}'`

fi
printf "\nUser Entered: %s\n" $var
# end script

Regards,


Nails


0
Reply to Message Icon

Related Posts

See More


AIX file size limit check if file is



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: need help on Unix program

Help on SCO Unix Network www.computing.net/answers/unix/help-on-sco-unix-network/2193.html

need help basic unix scripting: How www.computing.net/answers/unix/need-help-basic-unix-scripting-how/7050.html

Need help on shell programming www.computing.net/answers/unix/need-help-on-shell-programming/6386.html