Converting Coins


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting Coins
# 1  
Old 01-13-2009
Converting Coins

Hi all,

I have never written a script so I guess you could say I am very yellow.Smilie However, I could use some help.... I need to write a Korn Shell Script that converts coins. Meaning if I print or echo "Please enter amount:" and the user puts in 3.87, I need to know the least amount of coins that would equal the .87 cents.

Am I making any sense? I hope someone can give me a push in the right direction. Thanks in advance!!!
# 2  
Old 01-13-2009
Tools Practical appliation, or homework?

This really looks like a homework assignment. And while it looks to be an intriguing problem to try and solve, we do have rules against assisting on homework assignments.
The UNIX and Linux Forums - Forum Rules

So, if you can explain the reason behind the request as not homework or school-related, then please do.
# 3  
Old 01-13-2009
Bug

No, this is not homework. This is something I was asked to do to get me used to script writing. I have been looking online and through different books for an example and all I get is confused.
# 4  
Old 01-13-2009
(Delete this, I was too late)
# 5  
Old 01-13-2009
I have something on my mind, but if this is for training purposes there is no profit for you just to solve your problem. Try to workout something alone, post it here and I'm sure that a lot of good ideas will come.
Trust me there are a lot of scripting ninjas hereSmilie
# 6  
Old 01-13-2009
#!/bin/ksh
#Script name is coins
file=mynum

print -n "Please enter a 2 decimal digit between .01 and 1.00 to receive the correct amount of change: "
read num
if [[ $num = 0||$num -gt 101 ]];then
print "${num} is invalid."
fi
grep "$num" mynum


I did this small script and created the file mynum to accomodate the script and it worked but my boss said that isn't what he wanted. He is looking for something that can handle a number like "3.87" which my little program cannot handle. So I am looking for suggestions.

I also have this but it doesn't work:

$change
file=mynum
#!/bin/ksh
# Script name is: change

print -n "Please enter amount between 0 and 100:"
read num
if [[ $num = 0||$num -gt 100 ]];then
print "${num} is invalid."
fi
COIN=num
while read mynum
do
if [[ $mynum == $num ]];then
COIN=$mynum
export COIN
print "Your change is $COIN"
break
fi
done

Last edited by tzeman; 01-13-2009 at 12:06 PM..
# 7  
Old 01-13-2009
Ok. Let me get this straight.
You want to know the amount of COINS that will make the .87 cents,as in:
"your change is 3 quarters, one dime, and 2 pennies".
Is that correct?
Or is it that you want to know what the cents amount is in a given number? As in, say, if someone imputs 4.56, your script would reply:
"The change is .56 cents".

Which one is right?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help in converting

I have Excel file with the below three columns, i need your expertise in converting this to .csv file delimiter "|" Excel - Serial Number Serial Name Serial Brand 111 test sample 123 test2 sample1 134 ... (9 Replies)
Discussion started by: kiran_hp
9 Replies

2. Shell Programming and Scripting

converting empty value into NA

I have a set of values separated by a tab ch:12 1 3 4 ch:13 3 3 4 ch:25 1 8 ch:23 2 8 1 There is a missing value in the third column and i would like replace it with NA such that the final output would look like ch:12 1 3 ... (7 Replies)
Discussion started by: johnkim0806
7 Replies

3. Solaris

Help converting my Script

So i have been asked to write a script for a friend who has a server running solaris 11. My problem is the correct syntax i can't seem to get it work with the follow code, i have read through the date man page and found no work around Below is the code for part of the rsync script. The code i... (2 Replies)
Discussion started by: paperghost
2 Replies

4. UNIX for Advanced & Expert Users

Need help converting ctlU (^U) to a \12...

I have a file that ends with a ctlU: > cat -v test.file blah,blah,blah,GEAEA*1*xx0000111xxx^UIEA*xxx0^U would like to replace the ctlU (^U) with a "\12"...due to printers or something. I believe I might be able to utilize the tr command, if I could only identify the correct... (4 Replies)
Discussion started by: mr_manny
4 Replies

5. SCO

library converting

Hi everybody Is there any sco unix command to convert .so library to .a (under sco unix openserver.5.0.6) tnx (2 Replies)
Discussion started by: javad1_maroofi
2 Replies

6. Shell Programming and Scripting

Converting \0 to a \n

Hi - I have seen some similar posts but I am a bit stumped here below is the first line of a 'od -c filename' command. I want to change the \0 to \n 0000000 l s \0 c d - \0 c d . . \0 l s I have tried a sed construct in a script......... sed... (2 Replies)
Discussion started by: ajcannon
2 Replies

7. SCO

Converting

I use Sco_Sv 3.2v5.0.5 with parellel conection using dump terminals and i want to convert them to desktop pc. Anybody knows what hardware and other thing that would be involved? (3 Replies)
Discussion started by: seeyou
3 Replies

8. Shell Programming and Scripting

Converting to Uppercase

I want to convert string into uppercase string. How can i do that ? Ex: Enter the user name: read name show=upper(name) echo $show --- This output should be the uppercase output. Thanks (3 Replies)
Discussion started by: dreams5617
3 Replies

9. UNIX for Dummies Questions & Answers

converting .txt

Hello, I transferred some .txt files from windows to Unix. When i used the editor in Unix to open up the file, all the <cr> show up. How to I get rid of all of them? (4 Replies)
Discussion started by: laila63
4 Replies

10. UNIX for Dummies Questions & Answers

converting kb to mb

When I create filesystems in AIX i often get confused(using smit) When you specify size in aix, it is asked like this SIZE of file system (in 512-byte blocks) I never seem to grasp this, what is the equation to get say 500mb? Or is there a program anyone knows of that does this, like a... (1 Reply)
Discussion started by: csaunders
1 Replies
Login or Register to Ask a Question