![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Dec 2005
Posts: 2
Rep Power: 0
![]() |
A simple script isn't working correctly
I'm having trouble getting a very simple script to run and cannot figure out the problem. The script is as follows:
#!/usr/bin/perl -w
$level = 1;
$prod = (20 * $level) * (1.1 ** $level);
print "What is the amount of energy you\'re trying to accumulate? ";
chomp ( $goal = <STDIN> );
while ($prod <= $goal) {
# print "$level\n"; # DEBUG: print the current level
$level++;
}
print "\nRequired level for $goal energy from a solar planet is $level\n"; |
|
|
|
|
|
#2 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
$a = 2; $b = 3; $c = $a + $b; In order to change the value, you need to perform the calculation again: $b = 4; $c = $a + $b; |
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Dec 2005
Posts: 2
Rep Power: 0
![]() |
Thanks! Would changing this to a constant achieve my desired result, or would I need to just write a subfunction to repeatedly do the calculation?
|
|
|
|
|
|
#4 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
sub findProd {
my $level = shift @_;
return (20 * $level) * (1.1 ** $level);
}
...
$level++ while (findProd($level) <= $goal); |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|