Posts: 33
Threads: 8
Joined: Jan 2006
Hello guys. I have another problem this time.
I am trying to make a program that keeps on adding the number that is found.
Example:
1) User put input of how many time loop occurs.
2) 1 is first number then is added by itself. Then keeps going on like this
1 + 1 = 2
2 + 2 = 4
4 + 4 = 8
3) Then stops at the number they specified.
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 235
Threads: 30
Joined: Jun 2002
Code:
screen 12
dim loop_max as integer
dim number as integer
dim result as integer
result = 0
print "Enter number of loops"
input loop_max
print "Enter number to be multiplied"
input number
for count = 1 to loop_max
result += number
next
print result
sleep
if you have any question reguarding this just ask =)
url=http://www.smithcosoft.com]SmithcoSoft Creations[/url]
"If you make it idiot proof, someone will make a better idiot" - Murphy's Law
Posts: 6,419
Threads: 74
Joined: Mar 2002
That's not quite what he asked for.
Code:
n% = 1
Input "Iterations"; iterations%
For i% = 1 To iterations%
n% = n% + n%
Next i%
Print n%
Anyway, no need for loops:
Code:
Input "Iterations"; iterations%
Print 2^iterations%
Anyway, I'm not for posting code if the requester doesn't demonstrate he has, at least, tried. I did this time 'cause SSC's solution was for a different problem
Posts: 33
Threads: 8
Joined: Jan 2006
nathan none of them are working. The second one works but only squares it by 2. Im looking for like it to go up by 1 it self so when it finds a answer it does that one then when it gets that answer another.
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 6,419
Threads: 74
Joined: Mar 2002
My progs do what you specify in your first post. Explain it correctly, and we'll be able to help you.
Quote:1) User put input of how many time loop occurs.
2) 1 is first number then is added by itself. Then keeps going on like this
1 + 1 = 2
2 + 2 = 4
4 + 4 = 8
3) Then stops at the number they specified.
1, 2 and 3 just describe an algorithm to find a power of two.
Have you tried to solve this [strike]homework[/strike] problem? Show us what you got so far and we'll be able to help you fill in the gaps
And I don't understand this text:
Quote:Im looking for like it to go up by 1 it self so when it finds a answer it does that one then when it gets that answer another.
Posts: 33
Threads: 8
Joined: Jan 2006
nathan I mean like htis more clearly.
Say this is the program
******************************************************
Welcome to Program
How many Loops or whatever: 4
1+1=2
2+2=4
4+4=8
8+8=16
*****************************************************
Thats what I mean.. Gets the answer then it adds it self then does it again. Till the end of specification.
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 235
Threads: 30
Joined: Jun 2002
ya that what i made my code example to do, but i realized that you need to replace
with
so that its always adding to its self (including the first time)
url=http://www.smithcosoft.com]SmithcoSoft Creations[/url]
"If you make it idiot proof, someone will make a better idiot" - Murphy's Law
Posts: 33
Threads: 8
Joined: Jan 2006
SSC your code doesnt seem to work!! Ive got no idea what to do
img]http://img213.imageshack.us/img213/6104/sig1jb.gif[/img]
Posts: 2,771
Threads: 96
Joined: Oct 2003
Code:
input loops
number = 1
for i = 1 to loops
number = number + number
print number
next
If I understand exactly what he wrote... He wanted it to print the result every iteration.
Posts: 6,419
Threads: 74
Joined: Mar 2002
Our programs do exactly what the guy is asking for, only that they just give the final answer instead of showing every step.
If you want the program to output every step, you just have to add a PRINT to the loop, as KiZ mentioned. The changes are very simple and I think
you should try to do them. We are not here to do your homework, but to help you doing it