exercise from C++ How TO Program

This is a discussion on exercise from C++ How TO Program within the C++ Programming forums, part of the General Programming Boards category; Write a program that reads in the size of the side of a square and then prints a hollow square ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    2

    exercise from C++ How To Program

    Write a program that reads in the size of the side of a square and then prints a hollow square of that size out of asterisks and blanks. Your program should work for squares of all side sizes between 1 and 20.
    Last edited by cypherus; 01-07-2004 at 05:26 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,854
    You're missing the point - you try it for yourself first, then ask for help if you get stuck.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    14
    Cypherus, you got C++ How to Prgram 4th ed. by Deitel?

    I just recently started to get time to practice coding too, right now I'm working on the programs at chapter 4. I've learned that a good psuedocode and checking each function, new loop group, etc. helps out a lot. It really does help find bugs, since you know that the latest bug should have be caused by that new addition to the code.

    As for that problem, it isn't difficult, just take the square line by line. It's good to work the problems out first, then ask if you get a strange compiler error or syntax question.

    Hope the learning goes well!

  4. #4
    Registered User
    Join Date
    Jan 2004
    Posts
    2
    I'm using Deitel's Complete C++ Training course 4th ed. which includes C++ How To Program 4th edition.

  5. #5
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    So have a go at it yourself because the author of the book wouldn't give you the exercise if he hadn't already given you the knowledge to do it.

    If you can't do it, go over what you've already read again.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    62
    I am stuck the square as well i dont want to show what I done so far cause its embarasing, however to anyone who's done this question in the book, I belived I should be useing while loops
    even though I think its easier to do this with a for loop.
    Also am I right in thinking it should be nested loops?
    If you can just let me know I will get back to the drawing board, please no code as I want to do this myself. Its a fight you see.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >i dont want to show what I done so far cause its embarasing
    Then we can't help very much, can we?

    >however to anyone who's done this question in the book
    The problem is quite common, so you can be sure that just about all of us have done it. Some of us have done it countless times because the question shows up on these boards regularly.

    >Also am I right in thinking it should be nested loops?
    Generally, if you need to work with a box or a table whether it be input, calculations or output, nested loops are needed.

    >please no code as I want to do this myself
    So read the chapter again, work out the problem in your head and on paper, and then write the code. Unless somebody is generous enough to give you the answer, you're just wasting time here. We're more helpful when you show us an honest attempt, but even then we don't give much away for simple homework problems.

    >Its a fight you see.
    Perhaps you should take up another hobby then.
    My best code is written with the delete key.

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    62
    I was not going to answer you Prelude, but I will.

    Its a fight you see.
    Perhaps you should take up another hobby then.

    I find that a bit of an insult to be honest with you. It may be a fight but it would be a fight for anyone learning on their own out of a book. This Has been a life long dream and I attend to be good at it. I can't wait to really get good and design and programe some intreasting things.

    Also am I right in thinking it should be nested loops?
    Generally, if you need to work with a box or a table whether it be input, calculations or output, nested loops are needed.

    Well thats wrong for a start, you DONT have to have nested loops in the program. (mabey it works beter with them, but why make it hard for yoruself?)I'll be happy to show you my code, but it works fine.

    There I feel beter now thanks On to the next exercise in my book!
    The moral of the story for all you like minded new guys, Just cause someone has a lot of experience with programming dont mean they know best.

  9. #9
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    you DONT have to have nested loops in the program
    Which is why Prelude used the word, "generally".

    (mabey it works beter with them, but why make it hard for yoruself?)
    Why? You said it yourself. It may work better with them.

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I find that a bit of an insult to be honest with you.
    Take it as you will. I make no effort to make you feel good when you post the requirements for a common problem. This suggests that you want us to do it for you, or give you the answer. Clearly you didn't want help with your solution because you refused to post the code you had. We usually take this as a sign that you haven't even tried. While that isn't always the case, it's easier to generalize. So if you're insulted, tough. If you ask a poor question, you get a poor answer.

    >This Has been a life long dream and I attend to be good at it.
    That's wonderful, and a I wish you the best of luck. But you haven't gotten off to a good start here. First by not reading the rules, second by not searching the boards for previous answers, and finally by incorrectly correcting me.

    >Well thats wrong for a start
    An outer loop for the rows and an inner loop for the columns. How is that wrong? There are cases and tricks that avoid nested loops, but generally (if you had read my post instead of simply skipping over selected words) nested loops are needed. Before you correct somone, make sure you're right.

    >Just cause someone has a lot of experience with programming dont mean they know best.
    If you think you know better then why are you asking for our help? That was my first reaction, but that aside you're correct. It's your problem so you know what's best for you. However, most people that post here lack the experience to recognize all of the options. That's what we do; we show you different options. With the newfound knowledge that we offer, you are in a better position to select the correct option for your situation.

    I don't claim to know best when it comes to the design of your program simply because I don't know all of the details required for such complete understanding. However, it can be safely said that I've been there countless times (for this problem) and I'm well aware of the issues. If you choose to ignore my advice, that's fine. But don't assume that my advice is worthless. If you want to then that's fine as well, I'll be happy to ignore any further threads you start.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 11:58 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 08:51 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21