$Variable_B has asked for the wisdom of the Perl Monks concerning the following question:
Hello Wise and Helpful Monks, I have a question for you that troubles me...
Ok, so I got bored and I thought I would make a calculator as one of my first programs. I figured out how to make it do anything, but you had to change the script everytime you had a different problem or operator. Then, as time went on I learned more as we all do. I learned the concept of "<STDIN>" so that I wouldn't have to change the script for new variables because the user would input them. I ended up with this and this is far as I have gotten in my problem.
I have a problem though. As you can see I need to change the script if I want any other operation such as: subtraction, powers, multiplication, division, etc...
I haved asked in the CB and searched my books and the web but in vain, because I cannot find a way to make the user input the operation. I thought that this idea might look like....
$operator="<STDIN>"
but I was obviously and expectedly wrong.
Any ideas on how I can get this little operation input problem fixed?
-Variable_B
Ok, so I got bored and I thought I would make a calculator as one of my first programs. I figured out how to make it do anything, but you had to change the script everytime you had a different problem or operator. Then, as time went on I learned more as we all do. I learned the concept of "<STDIN>" so that I wouldn't have to change the script for new variables because the user would input them. I ended up with this and this is far as I have gotten in my problem.
#!/usr/bin/perl $a="<STDIN>"; $b="<STDIN>"; print "$a+$b\n";
I have a problem though. As you can see I need to change the script if I want any other operation such as: subtraction, powers, multiplication, division, etc...
I haved asked in the CB and searched my books and the web but in vain, because I cannot find a way to make the user input the operation. I thought that this idea might look like....
$operator="<STDIN>"
but I was obviously and expectedly wrong.
Any ideas on how I can get this little operation input problem fixed?
-Variable_B
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Inputing an Operator is it possible?
by dbp (Pilgrim) on Oct 07, 2002 at 03:19 UTC | |
by $Variable_B (Initiate) on Oct 07, 2002 at 03:30 UTC | |
by dbp (Pilgrim) on Oct 07, 2002 at 09:50 UTC | |
by dbp (Pilgrim) on Oct 07, 2002 at 10:10 UTC | |
by $Variable_B (Initiate) on Oct 09, 2002 at 00:33 UTC | |
by $Variable_B (Initiate) on Oct 09, 2002 at 00:36 UTC | |
by peschkaj (Pilgrim) on Oct 07, 2002 at 14:30 UTC | |
| |
Re: Inputing an Operator is it possible?
by krusty (Hermit) on Oct 07, 2002 at 03:12 UTC | |
| |
Re: Inputing an Operator is it possible?
by peschkaj (Pilgrim) on Oct 07, 2002 at 03:23 UTC | |
Re: Inputing an Operator is it possible?
by blahblahblah (Priest) on Oct 07, 2002 at 03:26 UTC | |
Re: Inputing an Operator is it possible?
by robartes (Priest) on Oct 07, 2002 at 08:44 UTC | |
Re: Inputing an Operator is it possible?
by fruiture (Curate) on Oct 07, 2002 at 11:12 UTC |
Back to
Seekers of Perl Wisdom