Example of "NaN script":
#!/usr/bin/perl use CGI; my $q = new CGI; my $summ = 100; my $peritem = 1; print "Content-type: text/html\n\n"; unless ($q->param('buyit')) { print "<HTML>You have $summ coins.<BR>All items cost $peritem coin +.<FORM>Enter number of items to buy<INPUT type=text name=items><input + type=SUBMIT name=buyit value=go></FORM>"; } else { my $num = int($q->param('items')); my $cost = sprintf("%.2f", $num * $peritem); print "<HTML>You try to buy $num items, for $cost coins.<BR>"; if ($cost > $summ) { print "You have not enough money<BR>"; } elsif ($cost < 0) { print "Invalid number<BR>"; } else { $summ-=$cost; print "You buy $num items for $cost coins. You have $summ coin +s left<BR>"; } }
Results:
** 23 coins: You try to buy 23 items, for 23.00 coins. You buy 23 items for 23.00 coins. You have 77 coins left ** 102 coins: You try to buy 102 items, for 102.00 coins. You have not enough money ** -3 coins: You try to buy -3 items, for -3.00 coins. Invalid number ** nan coins: You try to buy nan items, for nan coins. You buy nan items for nan coins. You have nan coins left

In reply to Re: Q: NaN again by kai
in thread Q: NaN again by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.