Posts: 488
Threads: 19
Joined: Sep 2005
Do exactly what KiZ said
Code:
input loops
number = 1
for i = 1 to loops
number = number + number
print number
next
And if it closes right away add Sleep to the end.
Posts: 650
Threads: 26
Joined: Aug 2004
i think he means this:
Code:
A = 1
do
A = A + A
? A
loop until [insert END number here ex: loop until a = 1048576]
quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
Posts: 33
Threads: 8
Joined: Jan 2006
Hey Kiz thanx it works a charm.. I tried to put a save function to save all numbers to a text file... I did this but it only saves the last number generated.
Code:
CLS
INPUT loops
number = 1
FOR i = 1 TO loops
number = number + number
PRINT number
NEXT
PRINT
INPUT "Save as: ", sf$
OPEN sf$ FOR OUTPUT AS #1
WRITE #1, number
CLOSE #1
Also how would I show the 1 + 1 = 2 instead of showing 2?
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 484
Threads: 14
Joined: Apr 2005
Code:
Dim ostr As String
CLS
INPUT "Loopa? : ", loops
number = 1
INPUT "Save as : ", sf$
OPEN sf$ FOR OUTPUT AS #1
FOR i = 1 TO loops
ostr = str(number) + " + " + str(number) + " = " + str(number + number)
Print #1, ostr
Print ostr
number = number + number
NEXT
CLOSE #1
EVEN MEN OF STEEL RUST.
Posts: 33
Threads: 8
Joined: Jan 2006
yetifoot I dont understand this line in your code
Code:
ostr = str(number) + " + " + str(number) + " = " + str(number + number)
and in qbasic it says it is a type mismatch in " + ".
Could anyone please explain?
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 1,439
Threads: 15
Joined: Apr 2003
Change str to str$ for QB.
Posts: 484
Threads: 14
Joined: Apr 2005
that line builds a string. sorry it didn't work i couldnt remember how to be QB compatible.
it builds ostr (a string variable that will contain the output ie 1 + 1 = 2)
ostr = str(number) + " + " + str(number) + " = " + str(number + number)
the '+' that is not within quotes is used to add strings together ie
Code:
s = "Hello "
s = s + "World"
Print s
Quote:Hello World
str is a function that changes a number variable into a string variable, so it can be added in this way.
hope that helps
EVEN MEN OF STEEL RUST.
Posts: 108
Threads: 0
Joined: Jan 2006
No need for a loop
Code:
dim b as integer
sub doubleit(seed as integer,bound as integer)
if bound>0 then
Print seed; " +" ; seed; " =" ; seed*2
doubleit seed*2, bound-1
end if
end sub
Print "Iterations:";
input b
doubleit 1,b
Note that in QB, b>14 will generate an error, and in FB b>30 will cause an oveflow. In fact, in FB, b=31 will oveflow to -2147483648 which means that b=32 will produce -2147483648 * 2 = 0, which means b=x when x>31 will result in the last x-31 results being 0+0=0
Posts: 324
Threads: 12
Joined: Nov 2005
Quote:Note that bad stuff will happen if you try - for some unknown reason - to do this recursively.
Ok, thanks for the advice. Skip the resursive function, Hybrid. :roll:
stylin:
Posts: 2,771
Threads: 96
Joined: Oct 2003
Im not sure Hybr!d is looking for a recursive function quite yet ;)
He is still trying to learn string concatenation :)