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 | |
} | |
?> |
Example running the demo
14:16:01 richardjortega@~/Dropbox/Code/phpeople/challenge_02_13_2014 (master) : php currency.php
Enter the amount in US dollars: $111
What currency do you want to convert to? (E)uros, (P)esos, (B)ritish Pounds: e
Psy Shell v0.1.1 (PHP 5.5.9 — cli) by Justin Hileman
>>> $money
=> "111"
>>> exit
Exit: Goodbye.
$111 is equivalent to 81.03 euros
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install:
Update Your
PATH
for global CLI use:Interactive Shell Use:
Debugger Use: