473,324 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Replacing value of a string and adding original value to an array?

Okay, so I want to create a loop that continuously asks for a set of three numbers, squares them, adds them together, then compares them. I'm not really done, so I apologize if you don't really get what I'm trying to do here.

Here's what I've got so far:


use warnings;

while(1==1){
print "Enter the first number: ";
$number1 = <STDIN>;
print "Enter the second number: ";
$number2 = <STDIN>;
print "Enter the third number: ";
$number3 = <STDIN>;

$total = $number3**2+$number2**2+$number1**2;
print "$total\n";

print "Are you done? Enter 1 for yes or 2 for no.\n";
$answer4 = <STDIN>;

if($answer4==1) {
last;
}
elsif ($answer4==2) {
redo;

}
}
## here I wanna compare the numbers
print "You have finished.";

I'm only a beginner at this, so I apologize if it's kinda simple.
But I want the scalar variable $total to be continuously re-evaluated for each time it loops, but add its original value to an array.

I don't really know if that's possible, but if it is, please help.
Jul 30 '10 #1
2 1265
toolic
70 Expert
What do you mean when you say "then compares them"? Compare what to what?

It is a good idea to chomp your input.
Jul 31 '10 #2
nithinpes
410 Expert 256MB
I am not sure what you want "to compare" here. But if you want to create the scalar fresh with each iteration, use 'my' (for local scope). You can later push each value into an array.

Expand|Select|Wrap|Line Numbers
  1. my $total = $number3**2+$number2**2+$number1**2;
  2. print "$total\n";
  3.  
  4. push @totals,$total;
  5.  
Aug 3 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: andrewcw | last post by:
Seems it should be simple. I had problems with a larger class and the newsgroup suggested something I also tried. So I pruned my class to see if I could find out what could be wrong, Still dont...
3
by: Andy Sutorius via DotNetMonster.com | last post by:
Hi, I have a Sorted List that has 9 key/value pairs. I am trying to take one of the key/value pairs and store the value of that key into a string variable. However, the value that actually gets...
4
by: David Bargna | last post by:
Hi I have a problem, I have a string which needs to be converted to a byte array, then have the string representation of this array stored in an AD attribute. This string attribute then has to...
2
by: John Dann | last post by:
Just wondering about the best way of assembling a string from a byte array in VB.Net. I have a sequence of Ascii characters read into a byte array from a binary file and need to reassemble these...
5
by: XML newbie: Urgent pls help! | last post by:
function to convert string to 1 dimensional array of long in VB.Net
1
by: Jim Michaels | last post by:
=> Array ( => UML:CLASS => open => 5 => Array ( => .:00000000000008EC => quiz_batteries => public
5
by: ApexData | last post by:
I have a bound textbox called txtMyBox with the current string value of "200". Once the user enters the textbox, and while the user is still in the textbox, I would like to check the changed value...
14
by: Aman JIANG | last post by:
hi i need a fast way to do lots of conversion that between string and numerical value(integer, float, double...), and boost::lexical_cast is useless, because it runs for a long time, (about 60...
2
by: pantagruel | last post by:
Hi, I have a service which does posting of messages dependent on CSV input. Dependent on what the first line of the CSV is different fields must be extracted and placed into a message. I would...
0
by: TBass | last post by:
I'm new to C#, and I have a question. For my program, I have 2 forms: one to allow the user to pick a property and another to allow the user to edit the property. They select the property they want...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.