thanks for all your great advice and wisdom...here is the somewhat finished code. I dont know what use strict is but I could not get the script to run correctly with it. I am sure it is a problem on my end and it is good advice...

I was suppossed to write a subroutine to process the arrays and hashes but I just ended up inserting the foreach loop to do that...not sure how to turn that section into a subroutine with global variables??

#!/usr/bin/perl -w #cash register and print receipt program my (@items, %qty, %price); #User input here print "Please enter your first and last name\n"; chomp (my $name = <STDIN>); print "Please enter your state sales tax in percentage (i.e. 7.75)\n"; chomp (my $tax = <STDIN>); $taxrate = $tax / 100; # enter loop to capture customer information here my $continue='Y'; while ($continue eq 'Y'){ print "Please enter an item or product name\n"; chomp ($itemname = <STDIN>); push @item, $itemname; print "Please enter the quantity of the item\n"; chomp ($itemquantity = <STDIN>); $qty{$itemname} = $itemquantity; print "Please enter the price of the item (no \$ please)\n"; chomp ($itemprice = <STDIN>); $price{$itemname} = $itemprice; print "Would you like to add another item? - Y or N\n"; chomp ($continue = <STDIN>); } # process subtotal and print receipt output here foreach $item (@item) { print "Item: $item\n"; $q_item = $qty{$item}; print "Quantity: $qty{$item}\n"; $p_item = $price{$item}; print "Price: \$$price{$item}\n"; $itemtotal = $q_item * $p_item; print "Item total: \$$itemtotal\n"; $subtotal += $itemtotal; print "Your current subtotal is: \$$subtotal\n"; } #print totals and tax here print "Purchase Subtotal: $subtotal\n"; print "Sales Tax Rate: $tax\n"; my $totaltax = $subtotal * $taxrate; print "Total Sales Tax = \$$totaltax\n"; my $totalamount = $subtotal + $totaltax; print "The total amount of this sale is: \$$totalamount\n"; #print the customer name and current date and time print "\n"; print "Customer: $name\n"; print "\n"; my $now = localtime time; print "Current Date and Time: $now\n";

also I tried an "if" statement to test the $continue variable for the proper answer but I could not get that to loop until the right answer "Y" or "N" was given so I took that bad code out

I can't tell you how much I appreciate your advice - I am learning slowly!

sierra


In reply to Re^6: seeking advice on loops by sierrastar
in thread seeking advice on loops by sierrastar

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.