Computer Science Canada

"Substring index is greater than length of string" (error)

Author:  gayden [ Mon Mar 02, 2015 10:17 am ]
Post subject:  "Substring index is greater than length of string" (error)

Task is to write a program that writes a wedge of stars. So, if you input a 7 into get x it'd look like this:
*******
******
*****
****
***
**
*

Here is my code:
code:
var x : int
put "Please enter the initial number of stars: " ..
get x
loop
    for i : 1 .. x
        put "*" (i) ..

    end for
    x := x - 1
    put ""
    exit when (x = 0)
end loop


When I run it I get an error on line 6.

I have no clue what a substring index is.

Author:  Insectoid [ Mon Mar 02, 2015 11:24 am ]
Post subject:  RE:"Substring index is greater than length of string" (error)

What is line 6 supposed to do? What does the (i) part mean?

Author:  gayden [ Mon Mar 02, 2015 3:28 pm ]
Post subject:  Re: RE:"Substring index is greater than length of string" (error)

Insectoid @ Mon Mar 02, 2015 11:24 am wrote:
What is line 6 supposed to do? What does the (i) part mean?

I believe it was Einstein that said something like: "We cannot solve our problems with the same thinking we used when we created them."

I think he's right because looking back at that line, I have no clue what I thought that should do.

Turns out all I had to do was remove the (i)..embarrassing.


: