![]() |
I'm creating a script that acts as a basic calculator. This will eventually be improved so it contains several advanced functions. Here is the problem that I have at the moment:
:
function Addition {When I enter 3 as the amount of numbers in the calculation, the loop always occurs four times and after that skips the next few lines and goes back to the Menu function, not providing me with the answer. Any ideas? |
the script doesnt loop 4 times, but you ask for a number before it starts.
example: 3 numbers insert one number: 1 then the loop starts to run 3 times, resulting in a total of 4 numbers the way around this is to do something like this: :
...should give you the desired result |
If your creating a script for linux there's one ether already installed and or availble for download on the net. I know you probally just doing this to learn scripting, but i'd thought that i would tell you that just in case.
|
Thanks for the help. Seems to make sense.
Quote:
|
ok, cool, just didn't want you re-inventing the wheel for nothing.
|
I didn't look at the above code, since i'm kinda on the go right now, but doing simple calculations on the commandline can be a lot less tedious. Maybe you could build something bigger from this:
:
$ echo '5+2*10/2' | bc |
Thanks for that - it does look easier. I'll try and work that into a future version. At the moment though I'm working on another Bash script where I enter the name of a particular folder, creates a tar file as a backup, and puts that tar file on my external hard disk. It'll save me from having to type out every script and re-rip every audio file if I have to reinstall Linux again.
|
| All times are GMT -5. The time now is 3:33 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC