December 18th, 2011, 01:10 PM
Loop structures, please help a newbie
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.
Loop: Day = 1 TO 5
Price = Price*0,9
Counter = Counter + 1
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.
Loop: Day = 1 TO 5
Price = Price * 0,9
If Price < WholesalePrice
Price = WholesalePrice
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.
December 18th, 2011, 02:36 PM
December 19th, 2011, 03:07 AM
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.
December 19th, 2011, 04:00 AM
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.
December 21st, 2011, 07:53 AM
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.