I need to write a program that accepts a number and finds an integer whose square is less than the number entered using only do loop and no other functions. I can use only one input and one output variable.
This is what I have and it's wrong:
cls
max=max-1
input "please enter a number"; max
do until max2<max
max2=(max*max)
loop
print max2
Can you help?
Beginner, Please Help
-
- Newbie
- Posts: 6
- Joined: Mon Oct 04, 2004 2:54 pm
- Location: Coming soon to a store near you
- Contact:
>I need to write a program that accepts a number and finds an integer whose square is less than the number entered using only do loop and no other functions.
The way you worded it, given the number is positive then 0 is a correct answer for any number. That's not too bad =) Your code wont work. I think you need to write what you want to do on paper and then do it in chronological order. This would do just fine:
Note the >=.
-abionnnn
The way you worded it, given the number is positive then 0 is a correct answer for any number. That's not too bad =) Your code wont work. I think you need to write what you want to do on paper and then do it in chronological order. This would do just fine:
Code: Select all
INPUT n&
i& = 0
DO UNTIL i&*i& >= n&
i& = i& + 1
LOOP
PRINT i& - 1
-abionnnn