• Please review our updated Terms and Rules here

Another CC-40 Program I can't get to work properly

mutantcamel

Experienced Member
Joined
Dec 14, 2007
Messages
76
This should be a simple one. What the program should do is ask me for 8 letters which can either be vowels or consonants and then display the results.

Well I'm using an old TI99 program which works to some extent. At the moment I'm only being allowed to pick only 6 letters, after my 6th choice, 8 letters are being returned on the screen. How this is happening, I have no idea!

(note the call key has only 2 variables not 3 like TI Basic!)

The program listing is:

100 RANDOMIZE
110 B1$="AEIOUY"
120 B2$="BCDFGHJKLMNPQRSTVWXZ"
130 PRINT "VOWEL OR CONSONANT (V/C) ?"
140 FOR CC=1 TO 8
150 CALL KEY (AW,S)
160 IF AW=86 THEN 190
170 IF AW=67 THEN 210
180 GOTO 150
190 C$=SEG$(B1$,INT(RND*6+1),1)
200 GOTO 220
210 C$=SEG$(B2$,INT(RND*20+1),1)
220 Z$=Z$&C$
230 NEXT CC
240 PRINT "YOU HAVE THE FOLLOWING"
250 PRINT "LETTERS: ":Z$

I'm sure this could be changed to something easier and I'm not sure about line 220, any ideas???
 
Last edited:
You appear to have a couple of errors in your code:

190 C$=SEG$(A1$,INT(RND*+1),1)

On 190, you aren't multiplying "RND" by anything. Should be "RND*6+1"???

210 C$=SEG$(A2,INT(RND*20+1),1)

On 210, you don't have the dollar sign "$" after A2, like you have after A1 in line 190.

Also, shouldn't "A1$" and "A2$" be "B1$" and "B2$"? Maybe I'm not understanding the SEG$ command correctly, but it should be similar in function to the old "MID$" function.

Line 220 is concatenating the contents of your string variable (Z$) with what ever you pick into C$. Looks ok to me.

There could be more, and I could be full of it. Like I said, I haven't written a lick of BASIC in more years than I care to count. ;-)
 
Guess what it's me, I typed out the program wrong last night on the forum. All those errors aren't in the program on my computer! It still doesn't bloody work though!

I have corrected it above, anyone else with any ideas???
 
Hmm..I have no idea what's wrong but this particular operation...
"Z$=Z$&C$" doesn't look like standard BASIC to me. It could be to add two strings together but in the versions of BASIC I'm familiar with that is acheived by a "+" sign not the "&". Try replacing the latter.
 
I've got a really stupid question here: What is CC-40? I'm not familiar with that.

As for your problem, tezza might be correct. Try changing line 220 from:

220 Z$=Z$&C$

to:

220 Z$=Z$ + C$
 
Re: CC-40

Re: CC-40

Never mind, I answered my own question (or rather Google answered it for me!)

CC40 = "TI Compact Computer 40"

And I verified that in TI BASIC, the "&" symbol is used for string concatenation, not the normal "+". No wonder TI got out of the home computer market! ;-)
 
Last edited:
Re: Another CC-40 Program I can't get to work properly

mutantcamel:

I installed BwBasic on my Linux computer and inputted your program (with certain changes required because of the different BASIC dialect), and got it to work. Here's the code I ended up with:

100 RANDOMIZE
105 Z$=""
110 B1$="AEIOUY"
120 B2$="BCDFGHJKLMNPQRSTVWXZ"
130 PRINT "VOWEL OR CONSONANT (V/C)? "
140 FOR CC=1 TO 8
150 INPUT; AW$
155 AW=ASC(LEFT$(AW$, 1))
160 IF AW=86 THEN 190
170 IF AW=67 THEN 210
180 GOTO 150
190 C$=MID$(B1$,INT(RND*6+1),1)
200 GOTO 220
210 C$=MID$(B2$,INT(RND*20+1),1)
220 Z$=Z$+C$
230 NEXT CC
240 PRINT "YOU HAVE THE FOLLOWING"
250 PRINT "LETTERS: ";Z$

The lines in bold are the ones that are different from your original listing.
I added line 105 to clear the Z$ variable between runs.
Lines 150 and 155 are due to BwBasic not having the "KEY" function like TI BASIC, and using INKEY$ is a pain.
Lines 190 and 210 use the "MID$" function instead of the "SEG$" function from TI BASIC. The two functions are, for the most part, identical in the parameters they accept, and the value they return.
Line 220 uses the "+" sign to concatenate the two string variables. TI BASIC uses the "&" sign.

I hope this helps!
 
Thanks for that Dr Pepper (I prefer Pepsi myself) but the thing still doesn't work. Everytime I run it, it allows me to press either 4,5 or 6 letters before coming up with the final 8 letters. I have other programs saved on the thing, but none of them should interfere with the program.

Before losing my tiny mind, I scrapped the idea and deleted the program. Maybe one day I'll go back to it again, maybe when I'm old and bald, but not anytime soon......

Thanks anyway :D
 
Here's my take on it.
I whipped this up in MBASIC.

A>MBASIC
BASIC Rev. 5.1
[CP/M Version]
Copyright 1977, 78, 79, 80 (C) by Microsoft
Created: 14-Jan-80
35035 Bytes free
Ok

100 RANDOMIZE TIMER
110 V$="AEIOUY"
120 C$="BCDFGHJKLMNPQRSTVWXZ"
130 Z$=""
140 PRINT "VOWEL OR CONSONANT (V/C) ?"
150 FOR N=1 TO 8
160 PRINT N;
170 INPUT A$
180 IF A$="V" THEN 220
190 IF A$="C" THEN 250
200 PRINT "OOPS"
210 GOTO 160
220 X=INT(RND(1)*6+1)
230 Z$=Z$+MID$(V$,X,1)
240 GOTO 270
250 X=INT(RND(1)*20+1)
260 Z$=Z$+MID$(C$,X,1)
270 NEXT N
280 PRINT "YOU HAVE THE FOLLOWING LETTERS:"
290 PRINT Z$

MBASIC doesn't seem to have INKEY, so I used a straight INPUT to collect the template.
In line 160, I print the position number so we know where we are in the template.

As for the CC-40 version, you might try it using simple variables.
(C instead of CC, or B$ instead of B1$)
I've run into versions of BASIC that don't realize, for example, that B1$ and B$ are different variables.

Cheers,
Andy
 
I couldn't stop tinkering :) so here's a version capable of arbitrary length templates:

100 RANDOMIZE TIMER
110 V$="AEIOUY"
120 C$="BCDFGHJKLMNPQRSTVWXZ"
130 Z$=""
140 PRINT
150 PRINT "INPUT TEMPLATE"
160 PRINT "VOWEL OR CONSONANT (V/C)"
170 INPUT T$
180 IF LEN(T$)=0 THEN 330
190 FOR N=1 TO LEN(T$)
200 A$=MID$(T$,N,1)
210 IF A$="V" THEN 250
220 IF A$="C" THEN 280
230 PRINT "OOPS"
240 GOTO 130
250 X=INT(RND(1)*6+1)
260 Z$=Z$+MID$(V$,X,1)
270 GOTO 300
280 X=INT(RND(1)*20+1)
290 Z$=Z$+MID$(C$,X,1)
300 NEXT N
310 PRINT "YOU HAVE THE FOLLOWING LETTERS:"
320 PRINT Z$
330 END

run

INPUT TEMPLATE
VOWEL OR CONSONANT (V/C)
? CVVCVC
YOU HAVE THE FOLLOWING LETTERS:
FAYMIB
Ok
 
DoctorPepper wrote:

I've got a really stupid question here: What is CC-40? I'm not familiar with that.

As for your problem, tezza might be correct. Try changing line 220 from:

220 Z$=Z$&C$

to:

220 Z$=Z$ + C$


I've never used CC-40 before though I'm just wondering if it would be worthwhile to change that line 220 to read Z$=Z$ and C$ since the original code is has an ampersand. The result should be different from Z$=Z$+C$ because 'AND' is a boolean operation, I would have thought that generic BASIC would incorporate the condition 'AND'.

CP/M User.
 
I'm just wondering if it would be worthwhile to change that line 220 to read Z$=Z$ and C$ since the original code is has an ampersand.

What should be the result of a Boolean "AND" across two string variables?
MBASIC complains that it's a "Type mismatch".

If you look at the entire program, not just that one line, the only thing that makes sense in that position is a string concatenation operator.
How it's implemented depends of the version of BASIC, and a previous post confirms that in TI BASIC it's the ampersand.
 
ahm wrote:

What should be the result of a Boolean "AND" across two string variables?
MBASIC complains that it's a "Type mismatch".

One things for sure MBASIC is not equal to CC-40!
I think that because C$ hasn't been defined properly as a "string" MBASIC is having a Whinge!
 
No, I don't think so. Most MBASIC dialects I know accomodate variables not being defined.

I do think it's more of a case of "&" being used to join strings together (concatenate) in the CC-40 BASIC as opposed to the more usual "+" in MBASIC.
 
tezza wrote:

No, I don't think so. Most MBASIC dialects I know accomodate variables not being defined.

Including Compilable versions of MBASIC?

I've never really dabbled with MBASIC to know for sure, I maybe thinking of CBASIC being more temperamental - there was a BASIC like that somewhere which wanted Strings defined, even though it's critically essential in Turbo Pascal when handling Strings! ;-)
 
Not sure about the compiled version of Microsoft's BASIC but most compiled languages seem a lot fussier about variable definitions so I wouldn't be surprised.

Certainly the interpreted BASICs I've played with (Microsoft's TRS-80 Level 2 BASIC, TRS-80 Model 100 BASIC, IMB BASICA (and GWBASIC), Commodore BASIC and OS Challenger's 8k BASIC (and I think CP/M MBASIC) variable type definition is optional. It's even optional in Atari BASIC which is not a Microsoft one.
 
Well I've modified the program so when you press either the v or c key, the random letter is printed on screen one at a time. I've found I've had to press the key a couple of times just to get a letter out. The keyboard seems fine when typing but the keys don't respond too well when executing the program!

I think the program works better that way. I've put a timer in there too and am going to get the computer to keep score on the winning word for each round for 2 players. The one with the longest word. I'm not sure if the latter will be easy yet. An 8 letter word scores 8 points...so how do I define that? Any ideas????
 
An 8 letter word scores 8 points...so how do I define that? Any ideas????

You might be able to do something with the LEN( ) function in BASIC. This function returns an Integer which is the length of the string in question.

So, if the string "osborne1" was assigned to the variable A$ somewhere earlier in the program and later you had

I=LEN(A$)

Then the variable I would be equal to 8. You could then use that variable in an IF..THEN construct to assign or accumulate a score value (or use it directly).

Again, most of the MS BASIC dialects I know assume that an undefined variable using just a letter is a single precision value. This works in a decision construct but it's good practice to define variable types at the start of the program. In this case if you know that "I" is always going to be an Integer (i.e. 1, 2, 3 etc. and not 1.1, 3.4 or 8.3) then just use
DEFINT I right at the beginning of the code. It will speed things up.

You might already know all this so sorry if I'm teaching you to suck eggs.

If BASIC is new to you though, it would be a good idea to get hold of a MBASIC reference book, which will list all the commands and functions. Some study of good programming practice would be also worthwhile.

I really like BASIC. It's easy to learn and you could do a lot with it in those days. MSBASIC is very forgiving though, and unless you imposed some self-discipline in the form of variable definition, sensible variable names, lots of REM comments, good error traps and logical layout hence avoiding too many GOTOs, the result could be spaghetti code which was hard to debug and maintain.

Looks like you're having fun though. Keep at it.
 
Last edited:
Back
Top