I just don't know what to do to end the damn loops!?!

#!/usr/bin/perl -w
use strict;



print "Welcome to Techno-Bank 3000.\n";

print "Enter command => ";
my $input = <STDIN>;
chomp $input;

my ($command, $user, $amount) = split / /, $input;
my %accounts = ( $user => $amount );

while( $command ne "Exit" ){
    if( $command eq "add" ){
        $accounts{$user} += $amount;
        print "done."
        }elsif( $command eq "withdraw" ){
            $accounts{$user} -= $amount;
            print "done."
        }elsif( $command eq "print" ){
            foreach (sort keys %accounts) {
                 print "$_ has $accounts{$_}";
        }}elsif( $command eq "exit" ){
               print "Goodbye.\n";
            }else{
                  print "Invalid command.";
                }
}


print "Enter command => ";
$input = <STDIN>;
chomp $input;

Sample input
Welcome to Techno-Bank 3000.
Enter command => add jacob 1000
done.
Enter command => add jacob 10000
done.
Enter command => this is fun
invalid command.
Enter command => add fil 1000
done.
Enter command => wd fil 20
done.
Enter command => print
Here are the accounts in Techno-Bank 3000.
jacob has 11000.
fil has 980.
Enter command => exit
Goodbye.

So stuck!!! HELP :) Please.

Recommended Answers

All 2 Replies

Cleaned up some...

#!/usr/bin/perl -w
use strict;

print "Welcome to Techno-Bank 3000.\n";

print "Enter command => ";
my $input = <STDIN>;
chomp $input;

my ($command, $user, $amount) = split / /, $input;
my %accounts = ( $user => $amount );

while( $command ne "Exit" ){
        if   ( $command eq "exit" ){
            print "Goodbye.\n";}
        
        elsif( $command eq "print" ){
            foreach (sort keys %accounts){
            print "$_ has $accounts{$_}\n";}}
        
       elsif( $command eq "add" ){
                        $accounts{$user} += $amount;
               print "done.\n";}
        
       elsif( $command eq "withdraw" ){
                        $accounts{$user} -= $amount;
            print "done.\n";}
        else{
            print "Invalid Command.\n";}

}
print "Enter command => ";
$input = <STDIN>;
chomp $input;

Still loops endlessly.

Well, your trying to match "Exit" and you entered "exit". It is case sensitive, you know.

If that is truly the case try the following

while ( uc($command) ne "EXIT" ) {

// instead of

while ( $command ne "Exit" ) {
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.