
-----------------------------------
kousha41564
Fri Dec 12, 2008 8:39 pm

making a diamond with *
-----------------------------------
hi , i am making a diamond with * (stars) and i did it after like 2 days of trying . but my code seems long and stupid, (programmer since 1 month, turing that is , i know html and basic) so here is the code, i was wondering if anyone could shorten it for me , if shortening it IS possible.


var nlines : int
var spaces : int
var stars : int
put "enter number of lines!"
get nlines
cls
put " "

spaces := nlines
for K : 1 .. nlines

    for decreasing H : spaces .. 1

        put " " ..

    end for

    spaces := spaces - 1

    for I : 1 .. K + K - 1
        put "*" ..
    end for

    put " "

end for


spaces := nlines
stars := nlines * 2 - 1
for K1 : 1 .. nlines

    for H1 : 1 .. spaces - (nlines - 1)

        put " " ..

    end for

    spaces := spaces + 1

    for decreasing I1 : stars .. 1
        put "*" ..

    end for
    stars := stars - 2

    put " "

end for
 

so the point of the program is asking how many lines the use would like, and then making a diamond based on that number of lines (twice that number of lines)

-----------------------------------
ecookman
Fri Dec 12, 2008 8:50 pm

Re: making a diamond with *
-----------------------------------
i don't think you can make the program shorter... turing is a horrible language to use

you need long complex programs to do simple things

as an example run this



var playerhp, monsterhp : int 
var playerattk, monsterattk : int 
var playerdef: int 
var onetwo : int
var monsterchoice: int

randint (playerhp,10,150)
randint (monsterhp,75,250)

loop
randint (playerattk,1,10)
randint (monsterattk,1,20)
randint (playerdef,1,15)
randint (monsterchoice,1,2)

delay(2000)

%player attack or defend
cls
locate (10,1)
put "your hp is ",playerhp
locate (11,1)
put "the monster's hp is ",monsterhp


locate (3,1)

put "press 1 to attack or press 2 to defend"
get onetwo
if onetwo = 1 then
    %player attacks 
    put "you hit a ",playerattk
    monsterhp := monsterhp-playerattk
    
    %monster decides what to do - attack or defend
        if monsterchoice = 1 then
            put "the monster attked and hit a ",monsterattk
            playerhp := playerhp-monsterattk
        end if
end if

if onetwo = 2 then
    %player defends 
    put "your defence is ",playerdef
    playerhp:=playerhp+playerdef
    %monster decides what to do - attack or defend
        if monsterchoice= 1 then
        put "the monster attked and hit a ",monsterattk
          playerhp := playerhp-monsterattk    
        
            
        end if
end if
if monsterhp