Here is the program:
# Variable Declarations
$us_dollars = 0;
$number_of_us_dollars = 3 ;
$us_dollar_total = 0.0;
$i = 1 ;
print("Welcome to the Money Exchange\n");
print("The program will convert three US dollar amounts to Danish, Krones, Euros and Hong Kong Dollars.\n");
print("First, please enter the exchange rates:\n");
do{
print("Danish Krones: "); # Reads the user input for Danish Krones
scanf
if ($danish_exchange <= 0)
{
print("Invalid entry. Please enter a number greater than 0.");
}
}while($danish_exchange <= 0);
do{
$euros_exchange = float(raw_input("Euros: ")) ;# Reads the user input for Euros
if ($euros_exchange <= 0)
{
print("Invalid entry. Please enter a number greater than 0.");
}
}while($euros_exchange <= 0);
do{
$hk_exchange = float(raw_input("Hong Kong Dollars: ")); # Reads the user input for Hong Kong Dollars
if ($hk_exchange <= 0)
{
print("Invalid entry. Please enter a number greater than 0.");
}
}while($hk_exchange <= 0);
# Begin for loop
for($i = 1; $i < $number_of_us_dollars; $i++){
# Dollar amounts are entered by user */
do{
$us_dollars = float(raw_input("\nEnter US dollars %i to be converted: " % (int(i))));
if ($us_dollars <= 0)
{
print("Invalid entry. Please enter a number greater than 0.");
}
else
{
print "\n The amount of %.2f US dollars is equivalent to:\n" % (float($us_dollars));
}
}while($us_dollars <= 0);
$danish_krones = $us_dollars * $danish_exchange ; #US dollars are converted to other currencies */
$euros = $us_dollars * $euros_exchange ;
$hong_kong_dollars = $us_dollars * $hk_exchange ;
print " %.2f Danish Krones\n" % (float($danish_krones)) ; # Display dollar value in the other currencies */
print " %.2f Euros\n" % (float($euros));
print " %.2f Hong Kong Dollars" % (float($hong_kong_dollars));
$us_dollar_total = $us_dollar_total + $us_dollars ; # Accumulator for total US dollars converted */
}
print "\nYou have converted a total of %.2f dollars.\n" % (float(us_dollar_total));
?>

New Topic/Question
Reply



MultiQuote







|