Thread: BASAL problem

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    3
    Rep Power
    0

    BASAL problem


    Hey, all
    Anybody here familiar with BASAL language?
    It's the first step in our class to learn C++. Now I'm STRUGGLING to write a program to calculate the least common multiple for two numbers in BASAL language. And the program should only consider the first twenty multiples of each number. Once the counters both exceed 20, it will show "no answer".
    I know basically, a outer while loop and an inner one are needed, but I just can't make them right!
    Here's what I have now. The LCM I got for 3 and 7 is 42!
    Please help!

    GET number1
    GET number2
    ASSIGN counter1 = (1)
    ASSIGN counter2 = (1)
    ASSIGN m1 = (number1)
    ASSIGN m2 = (number2)
    WHILE m1 != (m2)
    BEGIN
    ASSIGN m1 = (m1 * counter1)
    IF counter1 < (20)
    BEGIN
    WHILE m2 != (m1)
    BEGIN
    ASSIGN m2 = (m2 * counter2)
    ASSIGN counter2 = (counter2 + 1)
    IF counter2 >= (20)
    BEGIN
    ASSIGN m2 = (m1)
    ASSIGN answer = (-(1))
    END
    IF counter2 < (20)
    BEGIN
    ASSIGN answer = (m1)
    END
    END
    IF answer != (-(1))
    BEGIN
    SHOW "FOUND"
    SHOW answer
    END
    IF answer == (-(1))
    BEGIN
    ASSIGN m1 = (number1)
    ASSIGN m2 = (number2)
    ASSIGN counter1 = (counter1 + 1)
    ASSIGN counter2 = (1)
    END
    END
    IF counter1 >= (20)
    BEGIN
    ASSIGN m1 = (m2)
    ASSIGN answer = (-(1))
    SHOW "no answer"
    END
    END
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    248
    Find another class! How can any rational person think that teaching a totally unrelated language is the same as teaching C++? If you are at the level where you are learning basics about programming, you shouldn't be in a C++ class to begin with!

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by mitakeet
    Find another class! How can any rational person think that teaching a totally unrelated language is the same as teaching C++? If you are at the level where you are learning basics about programming, you shouldn't be in a C++ class to begin with!
    I know!
    And I doubt on which earth is the BASAL still used in programming...
    But this LCM thing is killing me right now. In the desired result, the two counters should equal 102. How fascinating!
  6. #4
  7. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    248
    Well, good luck finding someone who knows the syntax. I can state with certainty, though, that if you preserve indentation (if you didn't indent your original code, you should!) in your post using "code" tags you are much more likely to get some input, at least from a pseudocode analysis standpoint.

    Comments on this post

    • clifford agrees : In the HTML source for this page the text is only partially and inconsistently indented.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  8. #5
  9. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,119
    Rep Power
    1807
    Wher has all this come from all of a sudden!? You aren't working with this guy are you?


    You seem to have generated a lot of code for something very simple: http://www.mathsteacher.com.au/year7/ch03_prime/03_lcm/lcm.htm

    For values a and b, find m = MAX(a,b). You need a loop with an index i starting from 1. For each index test if m * i is a multiple of MIN(a,b). If BASAL has a modulo operator like C's % then if (m * i) MOD a == 0 then LCM = m * i. Increment i until you find LCM or until i == 20. Note that a * b is always a common multiple, so unless a or b are > 20 then there is always an answer.

    Comments on this post

    • SimonB2 agrees : Wondered the same thing.. Somehow managed to avoid making the same assertions as the above posts.
    Last edited by clifford; May 30th, 2012 at 10:12 AM.

IMN logo majestic logo threadwatch logo seochat tools logo