Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mishap in deducting values...
#1
ok take this bit of code here:

[syntax="qbasic"]
choice$ = LCASE$(INPUT$(1))
IF choice$ = "v" THEN item = item + 40 AND money! = money! - 2.25
IF money! < 0 THEN item = item - 40 AND money! = money! + 2.25 AND qq = 1
IF qq = 1 THEN GOTO 88
[/syntax]
basicly what this is is if i press "v" then the item get's a boost of 40.
but if i can't afford it, it sends me to line "88" where then it will tell me 'i can't buy that..." yada yada yada, but the problem is that when i do press "v" item = 0 for some reason.
quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
Reply
#2
The keyword AND is actually a boolean operator. You can't use it like the english word and.

It would be better to use an IF...END IF block...

Like this:


Code:
choice$ = LCASE$(INPUT$(1))

IF choice$ = "v" THEN
   item = item + 40
   money! = money! - 2.25
END IF


IF money! < 0 THEN
   item = item - 40
   money! = money! + 2.25
   qq = 1
   GOTO 88
END IF

Good luck!
Wink
Reply
#3
Replacing the AND words by a colon ":" should work fine.
Reply
#4
Dio,
[syntax="qbasic"]
choice$ = LCASE$(INPUT$(1))

IF choice$ = "v" THEN
item = item + 40
money! = money! - 2.25
END IF

IF money! < 0 THEN
item = item - 40
money! = money! + 2.25
qq = 1
END IF

IF qq = 1 THEN GOTO 88
[/syntax]

or

[syntax="qbasic"]
choice$ = LCASE$(INPUT$(1))

IF choice$ = "v" THEN item = item + 40 : money! = money! - 2.25

IF money! < 0 THEN item = item - 40 : money! = money! + 2.25 : qq = 1
IF qq = 1 THEN GOTO 88
[/syntax]

I prefer the previous over the latter.
Reply
#5
oh of course! sometimes i way over complicate stuff. :roll:
thanks
quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
Reply
#6
but that entire thing is waaay bloated. try something smaller like this:


[syntax="qbasic"]choice$ = LCASE$(INPUT$(1))
IF choice$ = "v" THEN
IF money! > 0 THEN item = item + 40: money! = money! - 2.25 ELSE GOTO 88
END IF[/syntax]

That does exactly the same job. Smile
Reply
#7
Nevermind, my bad..

[syntax="QBASIC"]'Code removed![/syntax]

... :wink:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#8
Not meaning to interfere, but the code sample Rattrap posted is definetely not the same as the original.

Try this following ultra-simple example to see what's the difference:
Code:
money! = 1
v$ = "v"

IF v$ = "v" THEN
   money! = money! - 2.25
END IF

IF money! < 0 THEN
   money! = money! + 2.25
END IF

PRINT money!
Code:
money! = 1
v$ = "v"

IF v$ = "v" THEN
   money! = money! - 2.25
ELSEIF money! < 0 THEN
   money! = money! + 2.25
END IF

PRINT money!

So please beware that you can't always use the simplified form for an IF block using ELSEIF, it results in different execution of the code.
Reply
#9
:o Nevermind my code,.. didn't see that.. Lucky I only use it for arrowkey scanning.. :wink:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#10
I don't like to use colons unless it's a limited line challenge that allows it. You might as well use code that's easier to read. Wink
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)