
-----------------------------------
netninja
Thu Feb 12, 2004 11:35 am

Help with string array,
-----------------------------------
% The "Average Speed" Program
setscreen ("graphics")

var AS: array 1..7 of string:= init ("starthour", "endhour", "startmin", "endmin", "totalhours", "distance", "totalmins") 
var font: int
font := Font.New ("serif:28")

Draw.Text ("Welcome to the Average Speed program", 6, 10, font, red)
Font.Free (font)


put "Please enter your Staring hour"
get AS (1)

put "Please enter Ending hour"
get AS (2)

put "Enter the starting minute"
get AS (3)

put "Enter the Ending minute"
get AS (4)

put "Please enter Distance travelled in KM"
get AS (6)

AS (5):= AS (2) - AS (1)
AS (7):= AS (4) - AS (3)



put "Your total time was ", AS (5)



put "Your average speed was "



Theres an end error, also, it says operands of '-',  must be integer, real, or compatible sets. So i tried with int, instead of string, but that would be confusing to somebody reading the code. I guess i could put a % note. But i donnno if my teacher would allow that. Anyone have an idea? Also, obviously the code isnt done, the end isnt complete, but im not concerned, i can fix it quick.

-----------------------------------
Andy
Thu Feb 12, 2004 11:44 am


-----------------------------------
u cant subtract a string from another... u can add tho

-----------------------------------
TheXploder
Thu Feb 12, 2004 1:01 pm


-----------------------------------
Why do you use string when you don't even need it when calculating integers? Try this:


% The "Average Speed" Program

var AS : array 1 .. 7 of int
var font : int := Font.New ("serif:28")
var additionalNum : string := ""

Draw.Text ("Welcome to the Average Speed program", 6, 10, font, red)
Font.Free (font)

for i : 1 .. 5
    case i of
        label 1 :
            put "Please enter your Staring hour"
        label 2 :
            put "Please enter Ending hour"
        label 3 :
            put "Enter the starting minute"
        label 4 :
            put "Enter the Ending minute"
        label 5 :
            put "Please enter Distance travelled in KM"
    end case
    get AS (i)
end for

AS (6) := AS (2) - AS (1)
AS (7) := AS (4) - AS (3)

if AS(6) < 10 then
    additionalNum := "0"
end if
put "Your total time was ", AS (6), ":", additionalNum, AS (7)
put "Your average speed was "


-----------------------------------
Cervantes
Thu Feb 12, 2004 3:50 pm


-----------------------------------
you can use strintok and strint but making the array of int would be much better.
