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

Username:   Password: 
 RegisterRegister   
 Extremely basic program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HB




PostPosted: Tue Mar 06, 2012 11:17 am   Post subject: Extremely basic program

What is the problem you are having?
I can't figure out how to generate a pattern in Turing using * with for loops



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
im looking to generate a Turing program that makes this pattern
Turing:


*
**
***
****
*****
******
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Tue Mar 06, 2012 12:40 pm   Post subject: RE:Extremely basic program

What have you tried so far?
QuantumPhysics




PostPosted: Wed Mar 07, 2012 12:26 am   Post subject: RE:Extremely basic program

use the character ASCII value of the star and have the user enter a bottom row value. Have the program out put that number of stars and reduce one everytime, or add one every time untill it gets to the max row number
S_Grimm




PostPosted: Wed Mar 07, 2012 9:03 am   Post subject: Re: RE:Extremely basic program

QuantumPhysics @ Wed Mar 07, 2012 12:26 am wrote:
use the character ASCII value of the star and have the user enter a bottom row value. Have the program out put that number of stars and reduce one everytime, or add one every time untill it gets to the max row number


Or you know, start at the first line and each time you go to a new line add another star to the output.

Take a look at For Loops inside For Loops.
HB




PostPosted: Wed Mar 07, 2012 10:40 am   Post subject: RE:Extremely basic program

Is there a tutorial for For Loops inside For Loops?
HB




PostPosted: Wed Mar 07, 2012 10:47 am   Post subject: RE:Extremely basic program

for y : 1 .. 8
for z : 1 .. y
put "*" ..
end for
put""
end for

muahahahahaha
S_Grimm




PostPosted: Wed Mar 07, 2012 12:50 pm   Post subject: Re: RE:Extremely basic program

HB @ Wed Mar 07, 2012 10:47 am wrote:
for y : 1 .. 8
for z : 1 .. y
put "*" ..
end for
put""
end for

muahahahahaha


Looks about right. I don't have access to a Turing Compiler at work, so I cant verify.
smool




PostPosted: Wed Mar 07, 2012 4:20 pm   Post subject: Re: Extremely basic program

Turing:

proc Star (numrows : int)
    for i : 1 .. numrows
        for j : 1 .. i
            put "*" ..
        end for
        put ""
    end for
end Star

Star (4)
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Wed Mar 07, 2012 4:42 pm   Post subject: Re: Extremely basic program

You can also use repeat. It's faster than nesting a for loop because you call put only once per line of '*'. On the other hand, you can't use it for lines with more than 255 '*'. (I assume that wouldn't be an issue though...)
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  [ 9 Posts ]
Jump to:   


Style:  
Search: