Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

loop problem

calculator loop

  • Please log in to reply
1 reply to this topic

#1 suicidal pencil

suicidal pencil

    CC Newcomer

  • Just Joined
  • PipPip
  • 23 posts

Posted 12 May 2008 - 02:38 PM

I've been toying with making a calculator in PERL, and I finally finished it!

when I go to run it, it runs perfectly...until it hits the part in the code where it's supposed to go into a loop. When it does, it should wait for me to type something. Instead, it loops the 'else' statement infinitely.

Can anyone help?

.
.
.
#INPUT
$input = <STDIN>;

print "*\n";

#the beginning portion of the program.

while ($while_lobby == 1){
print "Welcome, to the Command-Line Calculator Version two-point-oh.\n*\n";
sleep(3);
print "For file history, type in \'file history\'.\n*\n";
sleep(1);
print "If this is your first time using this, type in \'help\'\n";
sleep(1);
print "To start your hardcore calculating, type in \'go\'\n*\n";
$while_lobby = 0;
$while_wait = 1;
}

#This while loop patiently waits for you to make a decision.

while ($while_wait == 1){
if ($input eq "help"){
print "$help_block\n";
}
elsif ($input eq "file history"){
print "$file_history\n";
}
elsif ($input eq "go"){
print "going into the calculator. Remember the equal sign at the end!\n";
$while_wait = 0;
$while_calculator = 1;
}
else {
print "Unrecognized command. Type \'help\'\n"
}
}
.
.
.
.
.


Edited by suicidal pencil, 13 May 2008 - 06:54 AM.

  • 0

#2 suicidal pencil

suicidal pencil

    CC Newcomer

  • Just Joined
  • PipPip
  • 23 posts

Posted 13 May 2008 - 04:32 PM

whoops! I found my problem. When the program runs through the while loop, there is nothing telling it what '$input' is.

Scope will be my downfall. Feel free to lock, or delete this thread.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download