Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with string array,
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
netninja




PostPosted: Thu Feb 12, 2004 11:35 am   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Thu Feb 12, 2004 11:44 am   Post subject: (No subject)

u cant subtract a string from another... u can add tho
TheXploder




PostPosted: Thu Feb 12, 2004 1:01 pm   Post subject: (No subject)

Why do you use string when you don't even need it when calculating integers? Try this:

code:

% 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




PostPosted: Thu Feb 12, 2004 3:50 pm   Post subject: (No subject)

you can use strintok and strint but making the array of int would be much better.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: