#! /usr/bin/perl
$exp = "y";
while ($exp !="n") {
system "clear"; # clear the window
print "\nEnter the number of Widgets ordered: ";
$widgetcount = <STDIN>; #vairable to save the number of total widgerts ordered
chop $widgetcount;
print "\nEnter the number of Gidgets ordered: ";
$gidgetcount = <STDIN>; #vairable to save total number of gidget ordered
chop $gidgetcount;
print "\nEnter the number of Gadgets ordered: ";
$gadgetcount = <STDIN>; #variablet to save total number of gadget ordered
chop $gadgetcount;
print "\nEnter the number of Doodats ordered: ";
$doodatcount = <STDIN>; #vatiable to save total number of doodats ordered
chop $doodatcount;
$widgetsub = $widgetcount * 10.25; #subtotal of widgets
$widgetsub = sprintf("%0.2f", $widgetsub); #setprecesion two decimal places
print ("\nThe total number of Widgets ordered is: $widgetcount");
print ("\nThe total value of Widgets ordered is \$$widgetsub\n");
$gidgetsub = $gidgetcount * 5.75; #subtotal of gidgets
$gidgetsub = sprintf("%0.2f", $gidgetsub); #setprecesion two decimal places
print ("\nThe total number of Gidgets ordered is: $gidgetcount");
print ("\nThe total value of Gidgets ordered is \$$gidgetsub\n");
$gadgetsub = $gadgetcount * 11.33; #subtoal of gadgets
$gadgetsub = sprintf("%0.2f",$gadgetsub); #setprecesion two decimal places
print ("\nThe total number of Gadgets ordered is: $gadgetcount");
print ("\nThe total value of Gadgets ordered is \$$gadgetsub\n");
$doodatsub = $doodatcount * 44.75; #subtotal of doodats
$doodatsub =sprintf("%0.2f",$doodatsub); #setprecesion two decimal places
print ("\nThe total number of doodats ordered is: $doodatcount");
print ("\nThe total value of doodats ordered is \$$doodatsub\n");
#total of all subtotals without taxes and shipping charges
$total=($widgetsub + $gidgetsub + $gadgetsub + $doodatsub);
$total = sprintf("%0.2f", $total);
print ("\nTotal of all products subtotal is \$$total ");
$tax = $total*.10; #total tax on total amount
$tax =sprintf("%0.2f", $tax);
print ("\nThe total of all products tax is \$$tax");
$shipping = $total*.085; #total shipping charges
$shipping = sprintf("%0.2f", $shipping);
print ("\nThe total of all products shipping charges is \$$shipping");
$grandtotal = $total + $tax + $shipping; #grandtotal
$grandtotal = sprintf("%0.2f", $grandtotal);
print("\nThe grandtotal is \$$grandtotal \n");
print "Please enter 0 to quit: ";
$exp = <STDIN>;
chop $ex;
}
Try this,
while ($exp ne "n") {
system "clear"; ..............
..............
}
Try to read string comparison in Perl.
URL : String Comparison Operators
Use "ne" instead of "!=" in the condition. "!=" works out only for numbers.
#!/usr/bin/perl
$exp = "y";
while ($exp ne "n") {
system "clear"; # clear the window
print "\nEnter the number of Widgets ordered: ";
$widgetcount = <STDIN>; #vairable to save the number of total widgerts ordered
chop $widgetcount;
print "\nEnter the number of Gidgets ordered: ";
$gidgetcount = <STDIN>; #vairable to save total number of gidget ordered
chop $gidgetcount;
print "\nEnter the number of Gadgets ordered: ";
$gadgetcount = <STDIN>; #variablet to save total number of gadget ordered
chop $gadgetcount;
print "\nEnter the number of Doodats ordered: ";
$doodatcount = <STDIN>; #vatiable to save total number of doodats ordered
chop $doodatcount;
$widgetsub = $widgetcount * 10.25; #subtotal of widgets
$widgetsub = sprintf("%0.2f", $widgetsub); #setprecesion two decimal places
print ("\nThe total number of Widgets ordered is: $widgetcount");
print ("\nThe total value of Widgets ordered is \$$widgetsub\n");
$gidgetsub = $gidgetcount * 5.75; #subtotal of gidgets
$gidgetsub = sprintf("%0.2f", $gidgetsub); #setprecesion two decimal places
print ("\nThe total number of Gidgets ordered is: $gidgetcount");
print ("\nThe total value of Gidgets ordered is \$$gidgetsub\n");
$gadgetsub = $gadgetcount * 11.33; #subtoal of gadgets
$gadgetsub = sprintf("%0.2f",$gadgetsub); #setprecesion two decimal places
print ("\nThe total number of Gadgets ordered is: $gadgetcount");
print ("\nThe total value of Gadgets ordered is \$$gadgetsub\n");
$doodatsub = $doodatcount * 44.75; #subtotal of doodats
$doodatsub =sprintf("%0.2f",$doodatsub); #setprecesion two decimal places
print ("\nThe total number of doodats ordered is: $doodatcount");
print ("\nThe total value of doodats ordered is \$$doodatsub\n");
#total of all subtotals without taxes and shipping charges
$total=($widgetsub + $gidgetsub + $gadgetsub + $doodatsub);
$total = sprintf("%0.2f", $total);
print ("\nTotal of all products subtotal is \$$total ");
$tax = $total*.10; #total tax on total amount
$tax =sprintf("%0.2f", $tax);
print ("\nThe total of all products tax is \$$tax");
$shipping = $total*.085; #total shipping charges
$shipping = sprintf("%0.2f", $shipping);
print ("\nThe total of all products shipping charges is \$$shipping");
$grandtotal = $total + $tax + $shipping; #grandtotal
$grandtotal = sprintf("%0.2f", $grandtotal);
print("\nThe grandtotal is \$$grandtotal \n");
print "Do you want to Continue(y/n): ";
$exp = <STDIN>;
chop $exp;
$exp = lc($exp);
}