MakeWebGames

# Slight Problem

## Recommended Posts

This is probably really easy, but I just can't find out how to work it:

I would like it so that when a person attempts to buy a house they can't afford, it says how much more money they need to get the house....I have this:

`{\$np['hPRICE']} - {\$ir['money']}`

But that only outputs the house price minus the users money...but not the final answer. This also doesn't work:

`({\$np['hPRICE']} - {\$ir['money']})`

I thought I would need the ( and ), but no....

Cheers,

The Ace

##### Share on other sites

Re: Slight Problem

What?

House price: 100

User money: 80

100 - 80 = 20 ~ how much more they need

How isn't that right?

Unless you mean it just shows "You need 100 - 80", then do it outside of the string:

```\$need = number_format(\$np['hPRICE'] - \$ir['money']);
echo 'You need \$' . \$need . ' to buy the house';
```
##### Share on other sites

Re: Slight Problem

Grr...I get this: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /usr/home/*****/domains/***/public_html/newestate2.php on line 17

Here are my lines above and below the parse error:

```else if (\$np['hPRICE'] > \$ir['money'])
{
print "You do not have enough money to buy the {\$np['hNAME']} for £{\$np['hPRICE']}.
\$need = number_format(\$np['hPRICE'] - \$ir['money']);
echo 'You need £' . \$need . ' more to buy this house.'";```

This is line 17:

`\$need = number_format(\$np['hPRICE'] - \$ir['money']);`

Thanks for helping me!

Unless you mean it just shows "You need 100 - 80",

Yes...I did mean that! :-P lol.

##### Share on other sites

Re: Slight Problem

```else if (\$np['hPRICE'] > \$ir['money'])
{
print "You do not have enough money to buy the {\$np['hNAME']} for £{\$np['hPRICE']}";
\$need = number_format(\$np['hPRICE'] - \$ir['money']);
echo 'You need £' . \$need . ' more to buy this house.';```

You have to remember/learn where strings break, what is a string, what a string can do/contain, how its parsed

##### Share on other sites

Re: Slight Problem

Thank you very much! Works perfectly!

How do I get this: You do not have enough money to buy the White Hole for £1.5e+10. You need £14,999,800,000 more to buy this house.

to display: £15,000,000,000? Do I add a number_format after the £ sign and before {\$np['hPRICE']}. ";

Thanks again! :D

##### Share on other sites

Re: Slight Problem

Yeah, but you'll have to split up the string and concatenate it. Trust me it'll be better in the long run if I don't just hand it to you

##### Share on other sites

Re: Slight Problem

Yeah...good point. I'll have a go myself. Thanks.

##### Share on other sites

Re: Slight Problem

Yay! I did it myself...I just used another "need" function, but called it \$need2!

Thanks Deception! :)

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.