- #1
Femme_physics
Gold Member
- 2,550
- 1
Hey folks! Wow...been a while since I posted here.
So this ought to be a simple script I'm running in Command Prompt, but it completely skips the part where it asks the user to enter a number (after asking how much would you like to withdraw (or deposit) )
What gives?
So this ought to be a simple script I'm running in Command Prompt, but it completely skips the part where it asks the user to enter a number (after asking how much would you like to withdraw (or deposit) )
What gives?
PHP:
<?php
$balance=1000;
echo "Welcome to your bank. Your balance is " . $balance . " Which action would you like to take? (w=withdraw, d=deposit) \n" ;
$user=fgetc(STDIN);
if ($user=="w")
{
echo "How much would you like to withdraw? \n";
(int)$sum=fgets(STDIN);
$balance = $balance-$sum;
echo "Money successfully withdrawn. Your balance now stands at" . $balance . "";
}
else if ($user=="d")
{
echo "How much would you like to deposit? \n";
(int)$sum=fgets(STDIN);
$balance=$balance+$sum;
echo "Money successfully deposited. Your balance now stands at" . $balance . "" ;
}
else
{
echo "You can only use enter 'w' or 'd'";
}
?>