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

    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Question Loop structures, please help a newbie


    Hi!

    Could anyone please comment on my solution to the below mentioned problem? I feel so confused about using loop structures.(

    The Last Stop Boutique is having a five-day sale. Each day, starting on Monday, the price will drop 10% of the previous day’s price. For example, if the original price of a product is $20.00, the sale price on Monday would be $18.00 (10% less than the original price). On Tuesday the sale price would be $16.20 (10% less than Monday) and so on. Develop a solution that will calculate the price of an item for each of the five days, given the original price. Test the solution for an item costing $10.00.

    Here's what I've got.

    Read (Price)
    Loop: Day = 1 TO 5
    Price = Price*0,9
    Counter = Counter + 1
    LoopEnd: Day

    Second part of the same problem goes like this: Make changes in the solution to problem 1 to set the price at wholesale when the sale price drops below the wholesale price.

    Read (Price)
    Loop: Day = 1 TO 5
    Price = Price * 0,9
    If Price < WholesalePrice
    Price = WholesalePrice
    Endif
    LoopEnd: Day

    Thank you very much in advance! And please, do post a line or two, even if this seems like child play to you. I can't move on with my studies if I don't understand loops properly and I've failed to do so on my own.
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,673
    Rep Power
    1958
    The logic looks fine.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0
    Thank you for the comment, MrFujin! Can you tell me if I must include the 'Counter = Counter + 1' in both solutions and why/why not? I'm afraid this point isn't so clear to me.
  6. #4
  7. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,673
    Rep Power
    1958
    That depends which language you are working with.

    Your code (especially second part) is quite similar to the syntax for VB loop, in which case the counter is not needed.

    BTW, when you post (pseudo) code you should use the code tags.
    This will also keep any indentation/formatting your code may (should!) have.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0
    Thank you for your comments once again. I will use the code tags next time I post.

    Do you mind helping me with another problem? I'm afraid I'm not sure where to start.

    Mr. Brown has given a test to his class. He would like to have the average score for the class as well as the highest and lowest scores. Develop a solution to calculate and print out these values. (Use a trip value to stop the processing of the loop.)

    It sounds rather simple, but I don't know how to find the highest and lowest scores. I guess it should be smth like sorting the list first and then taking the 1st and the last value, but once again, I don't know how to present it. I would be extremely grateful if you could help me out here.

IMN logo majestic logo threadwatch logo seochat tools logo