Hi, I've been having issues with my program where I make the rocket do what its supposed to do when it comes to outputting a filled and hollow rocket body depending on either a odd or even value. The only problem I am currently having is duplicating the body length also known as adding stages of how long I want the boyd to be.
Here's my code:
[code]
//Draw a Rocket with a filled or hollow body with stages
#include <iostream>
using namespace std;
void drawOddBox(/* in*/ int, /* in */ int); //Function prototype with two value parameters
void getDimensions(/* out */ int&, /* out */ int&); //Function prototype with two reference parameters
void drawEvenBox(/* in*/ int, /* in */ int); //Function prototype with two value parameters
void drawHorizontalLine(int); //Function Prototype with one value parameter
void drawCone(); //Function prototype
int main()
{
int width = 5, numRows = 10, stages = 0;
//cout << width << " " << numRows << endl;
getDimensions(width, numRows); //A function call with two arguments
//cout << width << " " << numRows << endl;
if(numRows % 2 == 0)
{
drawCone(); //A function call to generate a cone
drawHorizontalLine(width); //A function call to generate a horizontal line
drawEvenBox(width, numRows); //Function call to generate a hollow box
drawHorizontalLine(width); //A function call to generate a horizontal line
drawCone(); //A function call to generate a cone
}
else
{
drawCone(); //A function call to generate a cone
drawHorizontalLine(width); //A function call to generate a horizontal line
drawOddBox(width, numRows); //A function call to generate a filled box
drawHorizontalLine(width); //A function call to generate a horizontal line
drawCone(); //A function call to generate a cone
}
cout << endl;
//drawFilledBox(numRows, width); //A function call with two arguments
return 0;
}
//Define all your functions below
//describe what the function will do and the role of the parameters
void getDimensions(/* out */ int& userInput1, /* out */ int& userInput2) //Function heading with two reference parameters
//Pre:
//Post:
{
cout << "Program will draw a filled box based on two dimensions" << endl;
cout << "WIDTH OF THE ROCKET BODY: ";
cin >> userInput1;
cout << "HEIGHT OF ROCKET BODY: ";
cin >> userInput2;
//Data range validation loop
while(userInput1 < 3 || userInput1 > 15 || userInput2 < 3 || userInput2 > 15 || !cin)
{
cin.clear(); //To clear cin fail state
cin.ignore(200, '\n'); //To ignore stray characters in the buffer
cout << "Dimensions input should be in the range of 3 to 15, please retype." << endl;
cout << "WIDTH OF THE BOX: ";
cin >> userInput1;
cout << "HEIGHT OF BOX: ";
cin >> userInput2;
}
}
void drawCone()
//Pre: Assume that no values are entered
//Post: Prints out a cone with three rows using a *.
{
cout << " *" << endl;
cout << " * *" << endl;
cout << "* *" << endl;
}
//describe what the function will do and the role of the parameters
void drawEvenBox(/* incoming data */ int width, /* in */ int numRows) //This is known as a function heading
//Pre: assume that two values are not negative or too large
//Post: A box is drawn with numRows and width limits
{
for(int row = 0; row < numRows; row++) //Outer loop generates new rows
{
for(int col = 0; col < width; col++) //Inner loop draws a single row
{
cout << '*';
}
cout << endl; //To move to the next row
}
}
void drawHorizontalLine(int x) //This is a "function definition"
{
int count;
for(count = 1; count <= x; count++)
{
cout << "*";
}
cout << endl;
}
void drawOddBox(/* in*/ int width, /* in */ int numRows)
{
int rowCount;
int spaceCount;
for(rowCount = 1; rowCount <= numRows-2; rowCount++)
{
cout << "*";
for(spaceCount = 1; spaceCount <= width-2; spaceCount++)
{
cout << " ";
}
cout << "*" << endl;
}
}
[/code]