Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Addition Loop Problem
#11
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.
Reply
#12
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
Reply
#13
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]
Reply
#14
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.
[Image: chav.gif]
Reply
#15
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]
Reply
#16
Change str to str$ for QB.
Reply
#17
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.
[Image: chav.gif]
Reply
#18
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
Reply
#19
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:
Reply
#20
Im not sure Hybr!d is looking for a recursive function quite yet ;)

He is still trying to learn string concatenation :)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)