Last active
August 29, 2015 13:57
-
-
Save richardjortega/9397258 to your computer and use it in GitHub Desktop.
currency phpeople challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('/Users/richardjortega/.composer/vendor/autoload.php'); | |
echo "Enter the amount in US dollars: $"; | |
$money = read_stdin(); | |
echo "What currency do you want to convert to? (E)uros, (P)esos, (B)ritish Pounds: "; | |
$currency = strtoupper(read_stdin()); | |
$converted = convert($money, $currency); | |
echo "$$money is equivalent to $converted euros\n"; | |
function convert($money, $currency) | |
{ | |
$conversion_dict = array( | |
"E" => 0.73, | |
"P" => 13, | |
"B" => 0.60 | |
); | |
\Psy\Shell::debug(get_defined_vars()); // breakpoint with interactive shell!! | |
$converted_value = $money * $conversion_dict[$currency]; | |
return $converted_value; | |
} | |
// our function to read from the command line | |
function read_stdin() | |
{ | |
$fr=fopen("php://stdin","r"); // open our file pointer to read from stdin | |
$input = fgets($fr,128); // read a maximum of 128 characters | |
$input = rtrim($input); // trim any trailing spaces. | |
fclose ($fr); // close the file handle | |
return $input; // return the text entered | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example running the demo