Thread: Full square

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    15

    Post Full square

    I would like to make a program that reads in the side of a square (between 1 and 20) and prints it out of (+ or - or * ). The simplest way possible, because im not that good at C++ yet.
    Last edited by iLike; 09-26-2009 at 06:10 PM. Reason: to clarify

  2. #2
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    Well... what have you tried?

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    15
    this is what i have now
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       int row;
       int column;
       int x;
    
    
    
      printf("Enter a number of row to be printed\n" );
       scanf ( "%d", &x );
    
       row = x;
       
       while ( row > 0 ) 
       {
            printf("*");
            row--;
       }
       printf("\n");
    
       row = x;
       column = x;
    
    return 0;
    
    }

  4. #4
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Filled square or empty square?

    If you are using C++ and not just C you should use cout/cin and not printf().

    Also this:
    Code:
       scanf ( "%d", &x );
       row = x;
    can be simply done like this:
    Code:
       scanf ( "%d", &row );
    Well, you print a line.Read also columns and reapeat "columns times" your program. And you will print eventually a square.

    Do some input checking if it is 1-20 if you want. Here is how your program should look (one way to do it)
    Code:
    while (columns > 0)
    {
       while (rows > 0)
       {
           //rest of code
       }
       //rest of code
    }

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    15
    Is there way to just use printf and loop?

    Code:
    int main(void)
    {
       int row;
       int column;
       int x;
    
    
    
      printf("Enter a number of row to be printed\n" );
       scanf ( "%d", &row );
    
       row = x;
       while (column > 0){
       while ( row > 0 ) {
            printf("*");
            row--;
       }
       printf("\n");
    
       row = x - 2;
       column = x;
       }
    return 0;
    }
    is this what you told me?

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    printf pwnz cout every day of the week, especially since cout is (or at least used to be) implemented using printf.

    plus its really easy to change a printf statement into a sprintf or fprintf, try doign a fcout or scout

    you can implement the whoel thing as a single for loop

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    15

    Question

    Can anyone tell me if its possible to do with printf and while and keep it simple( nothing like cout, cin, sprintf etc.), im just beginner. If it is possible can you tell me how should i modify my code?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tic Tac Toe Comp Move help
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 09-24-2008, 11:05 AM
  2. Loop seg error
    By Zishaan in forum Game Programming
    Replies: 2
    Last Post: 03-28-2007, 01:27 PM
  3. Forced moves trouble!!
    By Zishaan in forum Game Programming
    Replies: 0
    Last Post: 03-27-2007, 06:57 PM
  4. Help with my draughts game
    By Zishaan in forum C++ Programming
    Replies: 9
    Last Post: 03-24-2007, 07:33 AM
  5. hashing help
    By alokin in forum C Programming
    Replies: 17
    Last Post: 10-28-2002, 06:33 PM

Tags for this Thread