Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

use warnings; use strict; print "What is your name?"; 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)) { print "Please use numrals.\n"; 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"; { my $answer = <STDIN>; chomp $answer; if ("no" eq lc ($answer)) { print "Oh well, have a good day!"; exit; } if ("yes" ne lc ($answer)) { print "Please answer yes or no $name\n"; redo; } } print "The question is: What is the square root of 36?\n"; my $answertwo = <STDIN>; chomp $answertwo; 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 Hello, 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!

In reply to Re^2: Teaching Children How to Program by Panda
in thread Teaching Children How to Program by Sandy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-24 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found