im making a program using recursion to try and make a rectangle.
it .
heres the instructions
1. Rectangle Printer: Write a recursive function that draws a rectangle to the screen. Ask the user to enter positive integers for the height and width of the rectangle (error trap for bad input). Then ask the user for a character to use to print the rectangle (no error trap required). Then print the rectangle to the screen. No loops are allowed when printing the rectangle.
so if it said 5 * 5 with the filer a it would look like this
aaaaa
aaaaa
aaaaa
aaaaa
aaaaa
heres my code point me in the right direction
#include <iostream>
using namespace std;
void Rectangle(int height, int width, char filler);
void main()
{
int width;
int height;
char filler;
cout << "Printing a rectangle:\n\n";
cout << "Enter the height:";
cin >> height;
while (height <= 0)
{
cout << "The height should be greater than zero\n\n";
cout << "Enter the height:";
cin >> height;
}
cout << "Enter the width";
cin >> width;
while (width <= 0)
{
cout << "The width should be greater than zero\n\n";
cout << "Enter the width:";
cin >> width;
}
cout << "Enter a fill character:";
cin >> filler;
Rectangle(height, width, filler);
}
void Rectangle(int height, int width, char fill)
{
Or something like that. I made changes without recompiling and it fucked it up. It works with > 0 but prints an extra column and row, it breaks with >= 0. I dunno.
#include <iostream>
using namespace std;
void Rectangle(int height, int width, char filler);
void main()
{
int width;
int height;
char filler;
cout << "Printing a rectangle:\n\n";
cout << "Enter the height:";
cin >> height;
while (height <= 0)
{
cout << "The height should be greater than zero\n\n";
cout << "Enter the height:";
cin >> height;
}
cout << "Enter the width";
cin >> width;
while (width <= 0)
{
cout << "The width should be greater than zero\n\n";
cout << "Enter the width:";
cin >> width;
}
>>9 he helped me though so i dont mind him calling me a retard >>10 thanks man im gonna try and figure out how you did it so i can try to learn this recursion shit
Use a source code style that makes the code readable and consistent. Unless you have a group code style or a style of your own, you could use a style similar to the Kernighan and Ritchie style used by a vast majority of C programmers. Taken to an extreme, however, it's possible to end up with something like this: int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);
It is common to see the main routine defined as main(). The ANSI way of writing this is int main(void) (if there are is no interest in the command line arguments) or as int main( int argc, char **argv ). Pre-ANSI compilers would omit the void declaration, or list the variable names and follow with their declarations.
Functions are the most general structuring concept in C. They should be used to implement "top-down" problem solving - namely breaking up a problem into smaller and smaller subproblems until each piece is readily expressed in code. This aids modularity and documentation of programs. Moreover, programs composed of many small functions are easier to debug.
Cast all function arguments to the expected type if they are not of that type already, even when you are convinced that this is unnecessary since they may hurt you when you least expect it. In other words, the compiler will often promote and convert data types to conform to the declaration of the function parameters. But doing so manually in the code clearly explains the intent of the programmer, and may ensure correct results if the code is ever ported to another platform.
If the header files fail to declare the return types of the library functions, declare them yourself. Surround your declarations with #ifdef/#endif statements in case the code is ever ported to another platform.
Function prototypes should be used to make code more robust and to make it run faster.