Jump to content

Valda

New Members
  • Posts

    2
  • Joined

  • Last visited

Valda's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Two things I wanted to add, first is that I'm running it in Command Prompt Secondly that changing fgets to fgetc allowed me to define $user as string, however it completely skips "(int)$sum=fgets(STDIN);" Why?
  2. Howdy folks! Please go easy on me, I'm relatively new to programming and still climbing through the basics. My code is pretty simple. User gotta pick "d" or "w" to deposit or withdraw his fake virtual money, then he picks the amount and the awesomely cool calculation transpires But it doesn't work. No matter what is being picked the keyboard always goes to the "else" condition (which tells the user "You can only use enter 'w' or 'd'" -- despite the fact I input "d" or "w"). Basically it completely skips my "if" and "else if" statements. I tried putting "d" in quotations, without, with tags, with what not! So, any clue what is being done wrong here? <?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=fgets(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"; $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'"; } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.