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.
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
Well... what have you tried?
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; }
Filled square or empty square?
If you are using C++ and not just C you should use cout/cin and not printf().
Also this:
can be simply done like this:Code:scanf ( "%d", &x ); row = x;
Well, you print a line.Read also columns and reapeat "columns times" your program. And you will print eventually a square.Code:scanf ( "%d", &row );
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 }
Is there way to just use printf and loop?
is this what you told me?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; }
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
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?