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

Username:   Password: 
 RegisterRegister   
 How can I have the FOR LOOP output what loop it is on..?....
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HelloWorld




PostPosted: Tue Nov 09, 2004 6:18 pm   Post subject: How can I have the FOR LOOP output what loop it is on..?....

How can I have the FOR LOOP output what loop it is on..?....

I need my FOR LOOP to output which loop it is on so I can state which part number it is...

code:

    for counter : 1 .. n

        put "", skip
        put "PART", n %?? How can I do this?
        put "What is the part number? " ..
        get part (counter)

        put "How many of this part were purchased? " ..
        get quantity (counter)

        put "What is the parts name? " ..
        get pname (counter) : *

        put "What is the Net price of this part? " ..
        get netprice (counter)

        put "What is the Unit price for this part? " ..
        get price (counter)

    end for


Can anyone help me out with this? Thanks.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Tue Nov 09, 2004 6:24 pm   Post subject: Re: How can I have the FOR LOOP output what loop it is on..?

HelloWorld wrote:
How can I have the FOR LOOP output what loop it is on..?....

I need my FOR LOOP to output which loop it is on so I can state which part number it is...

code:

    for counter : 1 .. n

        put "", skip
        put "PART", n %?? How can I do this?
        put "What is the part number? " ..
        get part (counter)

        put "How many of this part were purchased? " ..
        get quantity (counter)

        put "What is the parts name? " ..
        get pname (counter) : *

        put "What is the Net price of this part? " ..
        get netprice (counter)

        put "What is the Unit price for this part? " ..
        get price (counter)

    end for


Can anyone help me out with this? Thanks.


The "counter" variable is already doing that for you.
HelloWorld




PostPosted: Tue Nov 09, 2004 6:35 pm   Post subject: (No subject)

Ha, sorry, I really should think harder before asking questions. Thanks though, it was easy (counter : n)...
HelloWorld




PostPosted: Tue Nov 09, 2004 6:38 pm   Post subject: (No subject)

Actually, I still have a problem, when I use:

code:

put "PART", counter : n


It works well, but depending on the value of 'n', it spaces out "PART" and the number.... like the higher the value of 'n' the more spaces there are between "PART" and the number.... How can I keep it just one spacing?
Hikaru79




PostPosted: Tue Nov 09, 2004 6:44 pm   Post subject: (No subject)

Remember, Letters are Left-aligned, numbers are right-aligned. As n increases, the "counter" has a larger field space to itself; and since it's at the right side of the field, it'll be farther away from "Part". For just ONE space, use:

code:

put "Part ", counter
HelloWorld




PostPosted: Tue Nov 09, 2004 6:49 pm   Post subject: (No subject)

Thanks for the help. And by the way......

Quote:

Letters are Left-aligned, numbers are right-aligned


I didn't know that, thanks again for the new knowledge!
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  [ 6 Posts ]
Jump to:   


Style:  
Search: