No such thing as a small change PerlMonks

### Re^2: Teaching Children How to Program

by Panda (Scribe)
 on Nov 14, 2005 at 09:54 UTC ( #508250=note: print w/replies, xml ) Need Help??

in reply to Re: Teaching Children How to Program
in thread Teaching Children How to Program

This is the first program I made. It's relatively simple but it helped me understand the basics.

```use warnings;
use strict;

my \$name = <STDIN>;
chomp \$name;
print "Hello, \$name:)\n";

print "How old are you? ";
my \$age = <STDIN>;
chomp \$age;
print "You are \$age years old!\n";
\$age = \$age / 2;
print "Half your age is \$age years.\n";
my \$sum;

{
print "Enter a number... ";
\$sum = <STDIN>;
chomp \$sum;
if (! isNumber (\$sum))
{
redo;
}
else
{
last;
}
}

my \$nextsum = \$sum / 2;
print "Half of \$sum = \$nextsum";
sub isNumber
{
my \$value = shift;
return \$value =~ /^[.\d+-eE]+\$/;
};
print "\nTell me \$name, would you like to try a test? Yes or No.\n";

{

{
print "Oh well, have a good day!";
exit;
}

{
redo;
}
}

print "The question is: What is the square root of 36?\n";
print "Correct! Have a good day!" if "6" eq lc (\$answertwo);

print "Sorry, you're wrong. Have a good day!" if "6" ne lc (\$answertwo
+);

As you can see, it goes like this:

```What is your name?your name
How old are you? 34
You are 34 years old!
Half your age is 17 years.
Enter a number... 5
Half of 5 = 2.5
Tell me your name, would you like to try a test? Yes or No.
yes
The question is: What is the square root of 36?
seven
Sorry, you're wrong. Have a good day!

Replies are listed 'Best First'.
Re^3: Teaching Children How to Program
by Tanktalus (Canon) on Nov 14, 2005 at 21:52 UTC

Oh, no - you've inherited the same indentation style!

:-)

(welcome, and good job .. much more ambitious than those silly 'hello world' programs ;-})

Re^3: Teaching Children How to Program
by ikegami (Pope) on Nov 16, 2005 at 02:00 UTC

<kidding>
I'm very interested in knowing the uppercase of "6" :)
</kidding>

Lots of goodies in there. Good stuff!

Create A New User
Node Status?
node history
Node Type: note [id://508250]
help
Chatterbox?
 [1nickt]: Discipulus Sorry had no time before. ++Test::Warn, but also simply Capture::Tiny to capture everything and examine it. Or just Test::Exception:: dies_ok().

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2018-01-22 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How did you see in the new year?

Results (233 votes). Check out past polls.

Notices?