
-----------------------------------
air_force91
Thu Nov 20, 2003 2:57 pm

&quot;for&quot; statements
-----------------------------------
here's the output i need to get:

5 4 3 2 1
These are small numbers


How do i get this? I know how to use the for and end for statement...im only supposed to use the statement to get those numbers but i get more than one sentences for "These are small numbers"...so how do i get the output as it is above? i need it ASAP...pls...thanx

-----------------------------------
Tony
Thu Nov 20, 2003 3:03 pm


-----------------------------------

for decreasing i: 5 .. 1
put i
end for


-----------------------------------
air_force91
Thu Nov 20, 2003 3:43 pm


-----------------------------------
that's the thing...that's the way i created my code but the numbers appear in columns...i want them to appear across the screen... :(

-----------------------------------
Mazer
Thu Nov 20, 2003 4:29 pm


-----------------------------------

for decreasing i : 5 .. 1
    put i, " "..
end for


-----------------------------------
Tony
Thu Nov 20, 2003 7:03 pm


-----------------------------------
unlike C++, turing always sticks newline character after each put statment. You have to place .. at the end of the put statment to get rid of new line as in Mazer's example

-----------------------------------
air_force91
Thu Nov 20, 2003 7:20 pm


-----------------------------------
thanx a lot...it really helped...another ques if u have time to answer it...ive written a program...it actullay ansks the user the name and calculates the average of three courses they're taking...

var name,answer:string 
var winID:int 
var mark,mark1,mark2,staverage:real 

winID:=Window.Open("position:top,center,graphics:640;640") 

loop 
put "Please enter your name: ".. 
get name 
cls 

put "Hello ", name, " Please enter marks for your first course: ".. 
get mark 
cls 

put "Please enter marks for your second course: ".. 
get mark1 
cls 

put "Please enter marks for your third course: ".. 
get mark2 
cls 

staverage:=(mark + mark1 + mark2)/3 

put "Your average is: ", staverage 
delay(10000) 
cls 

put "Would you like to continue(yes/no): ".. 
get answer 
loop 
if answer="no" then 
Window.Close(winID) 
end if 
end loop 
end loop


what i wanna know is that before the "end if"...i could include "elsif" if the user's answer is "yes"...my teacher said to use "randint" but whenever i type it in...i get this error saying there are no parameters or something...so what should i include if i want the loop part of my code to repeat itself if the answer is "yes"? and could u explaint the randint command to me?? thanx.... :lol:

-----------------------------------
Tony
Thu Nov 20, 2003 7:34 pm


-----------------------------------
:? your teacher wants you to have a random chance to exit the program?

anyways...

loop 
if answer="no" then 
Window.Close(winID) 
end if 
end loop 

thats a problem... this should not be in the loop. Just take the loop part out and everything should work fine.

-----------------------------------
air_force91
Thu Nov 20, 2003 7:44 pm


-----------------------------------
isn't ur bit of code same as mine? i don't get it...what is randint used for? ok u know how i have the "loop" inserted for the gathering of marks...well...if the user answers "yes" then is there a way i could just have the loop part (the marks part) repeat itself...i think this is where randint is used...? pls help me out....it's only been a week since ive learnt to program.... :cry:

-----------------------------------
Tony
Fri Nov 21, 2003 12:35 am


-----------------------------------
that bit of code is yours... that's where the problem is.

randint has nothing to do with loops. It is used to create a (pseudo) random number.

yours should be like

loop
...
your marks here
...
put "exit? y/n"
get answer

if answer = "y" then
exit
end if
end loop


so if user's answer is "y", if statment executes exit command, which jumps out of the loop. Otherwise if statment is skipped and program loops back to the beginning

-----------------------------------
Andy
Fri Nov 21, 2003 6:56 pm


-----------------------------------
u noe, having to put \n or endl after every line is kinda annoying...
