Trying to make a program involving groups...

New to FreeBASIC? Post your questions here.
chris00
Posts: 10
Joined: Jun 24, 2005 13:18
Location: england

Trying to make a program involving groups...

Postby chris00 » Jun 24, 2005 13:26

I set a variable as level$, and the text tells the user to type their character level in Final Fantasy 1. This value can be any number between
1 and 50. I want to know if you can set it so that if the person using this pogram types a number between 1 and 10, or 11 and 20 it displays two different sets of command for each set, so if input lies in between (and including) 11 and 20 it shows a message such as 'Good level, but need to work harder and if the input is greater than 50, it shows a message like:
'Cheater, you Sharked the game!'
Is this possible, because as far as I can see it only works with single digit numbers.
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Postby DrV » Jun 24, 2005 13:49

Either use an integer variable instead of a string one:

Code: Select all

Dim level as integer
Print "type your level:";
Input level
if level >= 11 and level <= 20
  print "good job"
else if level > 50 then
  print "cheater"
end if


Or use VAL:

Code: Select all

' assuming level$ has the level number
level_int = val(level$)
if level_int >= 11 and level_int <= 20
  print "good job"
else if level_int > 50 then
  print "cheater"
end if
{Nathan}
Posts: 301
Joined: Jun 04, 2005 15:18
Location: Ohio
Contact:

Postby {Nathan} » Jun 24, 2005 14:17

or you can use case

Code: Select all

input "Enter your level>"; level

select case level
case 1 to 10
print "You need more work..."
case 11 to 20
print "ok..."
case 31 to 50
print "whoa!"
case > 50
print "damnit cheaters"
end select
dumbledore
Posts: 680
Joined: May 28, 2005 1:11
Contact:

Postby dumbledore » Jun 24, 2005 15:09

string comparison's still doable by padding it with a space...

Code: Select all

if len(level$)=1 then level$=" "+level$
select case level$
case " 1" to "10"
? "n00b"
case "11" to "20"
'...etc
chris00
Posts: 10
Joined: Jun 24, 2005 13:18
Location: england

Postby chris00 » Jun 24, 2005 16:59

I tried Dumbledore's and Nathan's methods, but they both complain of a syntax error. My code follows:

Code: Select all

[start]
print "What is the level of a character of yours in Final Fantasy VII"
input "Level"; level
select case level
case 1 to 10
print "Just started eh? Keep at it newbie"
case 11 to 20
print "You're becoming quite the warrior. Keep at it!"
case 21 to 30
print "Wow, you're tough!"
case 31 to 40
print "You're strong enough to beat the Materia Keeper?! I had trouble at that!"
case 41 to 50
print "Ok, approaching the Overkill zone..."
case 51 to 60
print "Alright, now your getting SILLY!!!"
case 61 to 70
print "You're being ridiculous!"
case 71 to 80
print "Is the game easy enough yet?"
goto [start]
[/quote]
BTW changed to FF 7: Max on that game is 99 ^_^
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Postby DrV » Jun 24, 2005 17:02

Code: Select all

start:
print "What is the level of a character of yours in Final Fantasy VII"
input "Level"; level
select case level
case 1 to 10
print "Just started eh? Keep at it newbie"
case 11 to 20
print "You're becoming quite the warrior. Keep at it!"
case 21 to 30
print "Wow, you're tough!"
case 31 to 40
print "You're strong enough to beat the Materia Keeper?! I had trouble at that!"
case 41 to 50
print "Ok, approaching the Overkill zone..."
case 51 to 60
print "Alright, now your getting SILLY!!!"
case 61 to 70
print "You're being ridiculous!"
case 71 to 80
print "Is the game easy enough yet?"
end select
goto start


Note that you'll have to kill this manually with Ctrl+C or similar; adding a check for some kind of exit condition would be a good idea. :)
chris00
Posts: 10
Joined: Jun 24, 2005 13:18
Location: england

Postby chris00 » Jun 24, 2005 17:47

The error is on the following line:

Code: Select all

case 1 to 10

It says "BASIC compile halted:Syntax error"
What is the error?
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Jun 25, 2005 18:27

are you using freebasic? O_o

cant say ive ever seen the 'basic compile halted' message

and is it just me or does this seem like homework, lol
MystikShadows
Posts: 612
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

Postby MystikShadows » Jun 25, 2005 18:30

I think it's because of the default type level gets.

CASE are usually integer right? doesn't variable defaint to single in freebasic?

Just make sure you DIM level AS INTEGER and it should be good
v1ctor
Site Admin
Posts: 3801
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Postby v1ctor » Jun 25, 2005 18:39

The [label] syntax is used in LibertyBasic, are you sure you are using FREEBasic?

That "halted" error message doesn't exist in FB.

The default type is integer in FB, anything but UDT's can be used in Select's statements.
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Jun 26, 2005 0:54

stone him!!!!! :lol: jks
dumbledore
Posts: 680
Joined: May 28, 2005 1:11
Contact:

Postby dumbledore » Jun 26, 2005 1:11

there's no need to stone him, if he's in the freebasic forums when he's not using freebasic he's obviously already stoned. o_o

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests