Here's some recommendations for you:
Quote:
////////////////////////
// Greg Powell //
// 0221498 //
// Asignment #1 //
////////////////////////
This file header is way too complex. Having a border on the right is much more trouble than it's worth. Whenever you change a line to be longer you have to extend the entire border, making it a hassle.
Quote:
void stairsfromleft (int Length, int Height, int Numberstairs); //First type of staircase starting from the left
void stairsfromright (int Length, int Height, int Numberstairs); //Second type of staircase starting from the right
void convergingstairs (int Length, int Height, int Numberstairs1, int Numberstairs2); //Third type of staircase converging in the middle
int draw (int Length, int Startposition, int Drawtype, int Totallength, int Direction);
You should probably pick a better naming convention for functions. Analllowercasenamingconvention takes more effort to decipher than something like StairsFromLeft or stairsFromLeft. Also, you should almost always use verbs for function names. Also, the draw function doesn't specify what it's drawing in the name. If it's meant to draw the scene you should probably rename it to 'drawScene' or 'drawWorld.'
Quote:
int Length; //Length of stairs
int Height; //Height of stairs
You need to rethink these variable names. Renaming them so that they have 'Stair' in their names is much more readable than commenting it. Also, you should comment the type of units you are using.
Quote:
int Numberstairs1; //Number of stairs from the left
int Numberstairs2; //Number of stairs from the right
You should never put numbers in variable names. If they truly should be numbered, then you should put them in an array. You should probably reword those comments, they're fairly hard to understand. Also, you should think about using another naming convention for variable names.
Quote:
Length = (rand() % 2) + 3;
Height = Length / 2;
Numberstairs1 = (rand() % 5) + 2;
Numberstairs2 = (rand() % 5) + 2;
I see a lot of magic numbers here. Consider replacing them with named constants.
Quote:
for (Heightcounter = 0; Heightcounter < Height; Heightcounter++)
{
draw(Length, Startposition, DRAWTYPE1 , NO_LENGTH_REQUIRED, VERTICAL);
printf("\n");
}
I see duplicate code. You should put this into a seperate function.
Quote:
void convergingstairs(int Length, int Height, int Numberstairs1, int Numberstairs2)
{
int Staircounter;
int Heightcounter;
int Totallength;
int Startposition;
int Drawtype;
int Largernumberofstairs;
int Totalnumstairs;
Totalnumstairs = Numberstairs1 + Numberstairs2;
Totallength = (Length) * (Totalnumstairs);
if (Numberstairs1 == Numberstairs2)
{
Startposition = LEFT_START_POSITION;
Drawtype = DRAWTYPE3;
Largernumberofstairs = Numberstairs1;
for (Staircounter = 0; Staircounter < Largernumberofstairs; Staircounter++)
{
Startposition = draw(Length, Startposition, Drawtype, Totallength, HORIZONTAL);
printf("\n");
for (Heightcounter = 0; Heightcounter < Height; Heightcounter++)
{
draw(Length, Startposition, Drawtype, Totallength, VERTICAL);
printf("\n");
}
Totallength -= Length;
}
draw(Length, Startposition, DRAWTYPE1, NO_LENGTH_REQUIRED, HORIZONTAL);
printf("\n");
}
if (Numberstairs1 > Numberstairs2)
{
Startposition = LEFT_START_POSITION;
Drawtype = DRAWTYPE1;
Largernumberofstairs = Numberstairs1;
Staircounter = Numberstairs1;
while (Staircounter != Numberstairs2)
{
Startposition = draw(Length, Startposition, Drawtype, Totallength, HORIZONTAL);
printf ("\n");
for (Heightcounter = 0; Heightcounter < Height; Heightcounter++)
{
draw(Length, Startposition, Drawtype, Totallength, VERTICAL);
printf("\n");
}
Totallength -= Length;
Staircounter--;
}
Totallength += Length * (Numberstairs1 - Numberstairs2);
for (Staircounter = 0; Staircounter < Numberstairs2; Staircounter++)
{
Drawtype = DRAWTYPE3;
Startposition = draw(Length, Startposition, Drawtype, Totallength, HORIZONTAL);
printf ("\n");
for (Heightcounter = 0; Heightcounter < Height; Heightcounter++)
{
draw(Length, Startposition, Drawtype, Totallength, VERTICAL);
printf("\n");
}
Totallength -= Length;
}
draw(Length, Startposition, DRAWTYPE1, NO_LENGTH_REQUIRED, HORIZONTAL);
printf("\n");
}
if (Numberstairs2 > Numberstairs1)
{
Startposition = Totallength + Length;
Drawtype = DRAWTYPE2;
Largernumberofstairs = Numberstairs2;
Staircounter = Numberstairs2;
while (Staircounter != Numberstairs1)
{
Startposition = draw(Length, Startposition, Drawtype, Totallength, HORIZONTAL);
printf ("\n");
for (Heightcounter = 0; Heightcounter < Height; Heightcounter++)
{
draw(Length, Startposition, DRAWTYPE1, Totallength, VERTICAL);
printf("\n");
}
Totallength -= Length;
Staircounter--;
}
Startposition = LEFT_START_POSITION;
for (Staircounter = 0; Staircounter < Numberstairs1; Staircounter++)
{
Drawtype = DRAWTYPE3;
Startposition = draw(Length, Startposition, Drawtype, Totallength, HORIZONTAL);
printf ("\n");
for (Heightcounter = 0; Heightcounter < Height; Heightcounter++)
{
draw(Length, Startposition, Drawtype, Totallength, VERTICAL);
printf("\n");
}
Totallength -= Length;
}
draw(Length, Startposition, DRAWTYPE1, NO_LENGTH_REQUIRED, HORIZONTAL);
printf("\n");
}
}
This function should be broken up into other functions. Generally speaking, if you can't fit the whole function on the screen, it needs to be broken up. Also, >3 levels of nesting decreases the readability of a function. Whenever I program I try and keep the nesting level less than 3.
Quote:int draw (int Length, int Startposition, int Drawtype, int Totallength, int Direction)
{
int Returnvalue;
int Positioncounter;
char Space = ' ';
char Horizontaldash = '_';
char Verticaldash = '|';
if (Direction == HORIZONTAL)
{
switch (Drawtype)
{
case DRAWTYPE1:
for (Positioncounter = 0; Positioncounter < Startposition; Positioncounter++)
printf ("%c ", Space);
for (Positioncounter = 0; Positioncounter < Length; Positioncounter++)
{
printf ("%c ", Horizontaldash);
Startposition++;
}
break;
case DRAWTYPE2:
for (Positioncounter=Startposition; Positioncounter > Length; Positioncounter--)
printf("%c ", Space);
for (Positioncounter = 0; Positioncounter < Length; Positioncounter++)
{
printf ("%c ", Horizontaldash);
Startposition--;
}
break;
case DRAWTYPE3:
for (Positioncounter = 0; Positioncounter < Startposition; Positioncounter++)
printf ("%c ", Space);
for (Positioncounter = 0; Positioncounter < Length; Positioncounter++)
{
printf ("%c ", Horizontaldash);
Startposition++;
}
for (Positioncounter = Totallength; Positioncounter > Startposition; Positioncounter--)
printf ("%c ", Space);
for (Positioncounter = 0; Positioncounter < Length; Positioncounter++)
printf ("%c ", Horizontaldash);
break;
}
Returnvalue = Startposition;
}
if (Direction == VERTICAL)
{
switch (Drawtype)
{
case DRAWTYPE1:
for (Positioncounter = 0; Positioncounter < Startposition; Positioncounter++)
printf ("%c ", Space);
printf ("%c ", Verticaldash);
break;
case DRAWTYPE3:
for (Positioncounter = 0; Positioncounter < Startposition; Positioncounter++)
printf ("%c ", Space);
printf ("%c ", Verticaldash);
for (Positioncounter = Totallength; Positioncounter > Startposition + 1; Positioncounter--)
printf ("%c ", Space);
printf ("%c ", Verticaldash);
break;
}
Returnvalue = 0;
}
return Returnvalue;
}
This function also needs to be broken up.
I also recommend reading Code Complete; it has a truckload of information regarding readability and style. It does center around object oriented languages, but most of the stuff on procedures still apply.