Thread: Loop structures, please help a newbie

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    3

    Question Loop structures, please help a newbie

    Hi! I hope my post fits in Tech Board. If not, I'd be happy to move to to another location at cboard.

    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 (in pseudocode).

    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.
    Last edited by Helen Binet; 12-18-2011 at 12:54 PM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What weird language is this? You seem to be missing that crucial information.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    3
    Yes, sorry for not mentioning that beforehand. It's just a pseudocode.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    So do you expect replies in pseudo code too? Your code looks correct.
    If you have trouble with loops, I really recommend you check out flow charts. It's a graphical way of structuring up the logic of a program.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    3
    Exactly, pseudo code answers is what I'm looking for.

    That's good to know, thank you, Elysia. About the flowcharts, I've already covered them, although with no improvement in actually understanding the essence and design of loops. Right now I can merely adjust existing solutions to problems of a similar kind, while writing something even remotely different is still a bugger for me.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There are different kinds of loops.
    while loops while the loop condition is true. In flow charts, this would be a task such If Condition is true, do B, loop. If condition is false, break the loop.
    for loops are the same except they have initialization and post-instruction, so they would be Initialize, if condition is true, do B, do post condition, loop. Otherwise break the loop.
    Do while loops are while loops, but the condition pushed to the bottom, so do b, if condition is true, loop. Otherwise break the loop.
    You should easily be able to design such logic in flowcharts. Give it a shot.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help.. newbie for loop..stuck with the loop..
    By jochen in forum C Programming
    Replies: 15
    Last Post: 10-01-2007, 12:31 AM
  2. Replies: 3
    Last Post: 10-31-2006, 02:15 AM
  3. newbie question regarding usage of structures in class
    By samual_van in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2005, 10:51 AM
  4. Newbie question on Structures
    By Gatt9 in forum C++ Programming
    Replies: 15
    Last Post: 03-26-2005, 03:21 AM
  5. Newbie Help (Arrays, Structures, Functions,Pointers)
    By tegwin in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 06:29 PM