.. well, that's a heck of an assignment to get you to "get used to scripting". In any case..
I don't know what's in this file "mynum" that you are grepping from, but, for this particular situation I see 2 approaches here:
1.- The newbie
2.- The mathematician.
The newbie is simple: 100 cents is a small finite number, and having 4 types of coins to work with (pennies, nickels, dimes, quaters) further reduces the permutations. So, you can basically create a file with 100 lines that describe each possible combination of coins depending on the input:
Here what you would do, when the user inputs the amount, you'd grep myfile for that number and match it to a line in myfile that starts with that number, then output the rest of the line.
The mathematician, well, that one can get complicated. For that, you basically need to declare variables for each type of coin, then match the variables to the user input. There are probably 1000 ways to parse this: one approach would be to match the highest variable to the user input, once user input is less than variable, you'd add it to a numeric variable, then you go to the next highest variable, and so on. Something like:
Once TOTAL is less than Qtotal, Qcount will tell you how many quarters are in the original TOTAL, and TOTAL what is left, which should be less than 25 cents.
Then you'd use the same loop to figure out the dimes, then the nickels, then the pennies.
When you are finished, you can echo Qcount, Dcount, etc...
The loop will act something like this:
... and so on.
Get the idea?
Like I said, there are probably 1000 ways to work this, and I haven't tested the loops, but that should give you a start.
Last edited by System Shock; 01-13-2009 at 05:38 PM..
I have never written a script so I guess you could say I am very yellow. However, I could use some help.... I need to write a Korn Shell Script that converts coins.
If you are just learning shell scripting, learn to write scripts that will run in any POSIX shell (which includes Korn shell).
Quote:
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!!!
This is a relatively trivial exercise; it took me a couple of minutes and about a dozen lines of code.
A more interesting exercise would be to do it without a single-unit coin (but with other odd-denomination coins).
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)
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)
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)
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)
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)
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)
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)
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)
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)