Thread: Loop Problem..can you help please?

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    2

    Question Loop Problem..can you help please?

    Hi,
    I have program I am working on that will print out a square made out of astericks, depending on what the operator puts in. ie..4
    ***** The number entered must be between 4 and 20, between
    * * being the magic word. I can have it so that if you put in
    * * the number 21 or higher, it gives the operator an error
    * * statement. Great! But when I put in 4, it begins a loop.
    ***** Any help on this irratating problem would be most appreciated.. Thanks..Debbie

    /* Action begins here. */

    printf("Make a square out of astericks!\n");

    printf("Enter a number between 4 and 20:\t \n");
    scanf("%d", &limit);


    /*Checking to see if entered number is between 4 and 20*/
    while ( limit < 4 || limit > 20) {
    printf("Again, please enter a number between 4 and 20: \n");
    scanf("%d", &limit);
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    for 4...
    Code:
    *****
    *   *
    *   *
    *   *
    *****
    Just look at what the lines you print are, and how many times you print 'm...


    1. Prints a line of 5 (that is... 4 +1) *s (loop here)
    2. Prints 3 lines of * * (that is, 4 - 1 lines... each line has 4 - 1 spaces... you're going to have to use two loops here)
    3. Prints a line of 5 (that is 4 + 1) *s (loop here)

    So you'll need a loop that can print n + 1 *s

    You'll need a loop that can print * * with n - 1 spaces

    And you'll need a loop which can call that last loop n - 1 times.
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    2

    Thumbs up

    Thank you!!
    Sorry it took so long to reply..flu hit here.. How much fun it was to be a mom, do the homework/programs, loose time at work and still try to maintain a sick house!

    Your help was GREAT...Took me a bit but it fell into place! Thanks again!
    Debbie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Addition problem in loop
    By murjax in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 06:29 PM
  2. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  3. For Loop Problem
    By xp5 in forum C Programming
    Replies: 10
    Last Post: 09-05-2007, 04:37 PM
  4. Loop problem
    By Tesnik in forum C++ Programming
    Replies: 29
    Last Post: 08-23-2007, 10:24 AM
  5. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM