Entering edit mode
10.3 years ago
Sidney
•
0
print"Please enter the starting number of organisms:";
$organisms=<STDIN>;
chomp($organisms);
}
print"Please enter the average daily population increase (as a percentage):";
$increase_perc=<STDIN>;
chomp($increase_perc);
if ($increase_perc==0) {}
print"Please enter the number of days they will multiply:";
$days=<STDIN>;
chomp($days);
}
$count=$organisms;
foreach ($days){
$count++;
if ($days==1) {
print"Day\tOrganisms\n\n";
print"---------------------\n\n";
print"1\t\t$organisms\n";
}
if ($days==2) {
$result=int(($organisms * $increase_perc)/100)+$organisms;
$count++;
print"Day\tOrganisms\n\n";
print"---------------------\n\n";
print"1\t\t$organisms\n";
print"2\t\t$result\n";
}
if ($days==3) {
$result3=int($result)+$organisms;
print"Day\tOrganisms\n\n";
print"---------------------\n\n";
print"1\t\t$organisms\n";
print"2\t\t$result\n";
print"3\t\t$result3\n";
}
if ($days==4) {
my$result_4=($line3 + $organisms)+ $organisms;
$line4=($result + $organisms) * 4;
print"Day\tOrganisms\n\n";
print"---------------------\n\n";
print"1\t\t$organisms\n";
print"2\t\t$line\n";
print"3\t\t$line3\n";
print"4\t\t$line4\n";
}
}
None of my output is working. Please help
Output should be:
Day Organisms
-----------------------------
1 2.0
2 3.0
3 4.5
4 6.75
5 10.125
6 15.1875
7 22.78125
Thanks for looking at my question. I have updated the program to reflect the change you indicated:
while($count < $days){$count++}
But I'm still not sure how to format the output, without repeating each value over and over?
is this an assignment? It certainly sounds like one, since this problem would typically be solved analytically. I'm afraid I shall not be giving you anymore help
I am simply trying to understand how I can go about solving the problem. Any direction you can point me in would be greatly appreciate. I am not looking for an answer, but a way I can solve this on my own. When you said there are other issues, could you please explain?
Try writing a program using a while loop or a for loop but without any if / else that prints out the folowing (with the header):
Maybe you could go through couple of "Introduction to Perl" manuals before trying to solve real problems and asking for help.