in reply to string functions
There are many errors or weird things in your program
my %value = ( A => 1.5, B => 2.5, C => 3.5, ); my %factor = ( A => 50/100, B => 55/100, C => 60/100, );
You can then easily split up your string and calculate the numbers.
my @letters = split //, $expanded_string; my $result = 0; for my $letter (@letters) { $result = $result + $value{ $letter } * $factor{ $letter }; }; print $result;
With these changes, I get a result of 8.45, so either your calculation of 28.4238 is wrong or you need to explain how you arrive at that number. Basically, my code calculates the following number:
$result = 1.5 * (50/100) * 2 + 2.5 * (55/100) * 2 + 3.5 * (60/100) * 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |