Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to 'manipulate' strings in BASIC V2?

I would like to reach the following: I ask for a number from the user, and then output a string like the following:

-STR$

--STR$

---STR$

----STR$

-----STR$

I tried to do this:

10 INPUT NUM%
20 FOR X=1 TO NUM%: PRINT NUM%*"-" + "TEXT" : NEXT

The code above got me an error: ?TYPE MISMATCH EROR IN 20

However, I didn't yet figure out how to manipulate the string's beginning to multiply the '-' marks on each loop run

like image 673
K. Gero Avatar asked Apr 13 '26 23:04

K. Gero


2 Answers

Maybe this:

10 INPUT NUM%
20 FOR I = 1 TO NUM%
30 FOR J = 1 TO I: PRINT "-"; : NEXT
40 PRINT " TEXT"
50 NEXT

There is no multipy of strings/character, as far as I remember to old (good) times.

like image 173
MiniMik Avatar answered Apr 16 '26 12:04

MiniMik


I believe even older, more primitive forms of BASIC had the STRING$() function. It takes two parameters: the number of times to repeat the character and the character itself. So...

10 INPUT NUM%
20 FOR X=1 TO NUM%: PRINT STRING$(NUM%, "-") + "TEXT" : NEXT
like image 32
Bill Hileman Avatar answered Apr 16 '26 12:04

Bill Hileman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!