I need to output picture of a rocket using * the program works. The top of the rocket doesn't line up with the body of the rocket. Can someone point me in the write direction on how to start it. the function i am using is called drawCone.

#include <iostream>
#include <iomanip>
using namespace std;

void drawCone()
{
    cout << "  *  " << endl;
    cout << " * * " << endl;
    cout << "*   *" << endl;
}

void drawBox(int height, int width)
{
    int i, j;
    int number_of_stages ;
    cout << " How many stages do you want in your rocket:";
    cin >> number_of_stages;
    
    drawCone();

    for(j = 0; j < number_of_stages; j++)
    {
	
	for(i=0; i<width; i++)
	{
            cout <<"*";
	}
        
	cout <<endl;
	
	for(i = 0; i < height; i++)
	{
            cout << "*";
	    cout.width(width-1);
	    cout << "*" << endl;
	}
	
	for(i=0; i<width; i++)
	{
	    cout<<"*";
	}

	cout <<endl;
    }
    
    drawCone();
}
int main()
{
    cout << "Today we will output a picture of a rocket using the symbol of an astrick." << endl;
    
    int height, width;
    
    cout << "Enter the width of what your rocket should be " << endl;
    cin >> width;
    
    cout << "Enter the height of what your rocket should be MM " << endl;
    cin >> height;

    drawBox(height, width);
    
    
    return 0;
}

Recommended Answers

All 8 Replies

Does your draw cone function consider the width of the rocket?

That is what i dont know how to do account in the width and adding space in between the next line

I got it work somewhat how do i remove the extra * and add spaces in between. this is my output

Enter the width of what your rocket should be:6
Enter the height of what your rocket should be:4
How many stages do you want in your rocket:2

******
******
******
******
******
******
******
*    *
*    *
*    *
*    *
******
******
*    *
*    *
*    *
*    *
******
******
******
******
******
******
******

the code i added to the drawCone function

void drawCone(int width)

{

    int count;
    int innerCount;
    
    count = 1; 
   
    while (count <= width) 
    {
      innerCount = 1;
      while (innerCount <= width)
      {
            cout << "*";
            innerCount++;
      }
      cout << endl;
      count++;
     
   }

}

I got it work somewhat how do i remove the extra * and add spaces in between.

What extra * and add spaces where?

Try drawing out your cone on graph paper for different rocket widths. Then look at the pattern for number of spaces in each line and where the *s are. There will be a definite number progression which is easily coded.

You will have to make a decision about your cone drawing because you will encounter 2 different types of cone -- odd and even width. If it is an odd width, it is easy to put the tip of your cone in the middle, but how would you deal with an even width? You need to solve that before you start programming.

To add a space between your rocket, add another endl in your first post code line 43.

I have narrowed the program where I just need to add the tip of the cone and hollow out the cone.

Enter the width of what your rocket should be
8
Enter the height of what your rocket should be MM
4
How many stages do you want in your rocket:2

**
  ****
 ******
********
********
*      *
*      *
*      *
*      *
********
********
*      *
*      *
*      *
*      *
********
   **
  ****
 ******
********

the cone function
also the width has been changed from a local variable to a global variable.

void drawCone()

{  
void drawCone()

{   

    int count;
    int innerCount;

    count = 1;

if (width % 2 == 1)
{         
          while (count <= (width/2)) 
          {
                innerCount = 1;
                while (innerCount <= ((width)/2) - count)
          {
                cout << " ";
                innerCount++;
          }
               innerCount = 1;
               while (innerCount <= count)
          {
               cout << "*";
               innerCount++;   
          }
                innerCount = 1;
                while (innerCount <= ((width - 2)/2) + count)
          {
                innerCount++;
          }
                innerCount = 1;

         while (innerCount <= count)
          {
                cout << "*";
                innerCount++;
          }
                cout << endl;
                count++;
          }
}

if (width % 2 == 0)
{         
          while (count <= (width/2)) 
          {
                innerCount = 1;
               while (innerCount <= ((width)/2) - count)
          {
                cout << " ";
                innerCount++;
          }
                innerCount = 1;
                while (innerCount <= count)
          {
                cout << "*";
                innerCount++;
          }
                innerCount = 1;
                while (innerCount <= ((width)/2) + count)
          {
                innerCount++;
          }
                innerCount = 1;

          while (innerCount <= count)
          {
                cout << "*";
                innerCount++;
          }
                cout << endl;
                count++;
          }
}
}

the cones look uneven but they line up correctly it was not formatting correctly. Just need to know how to add tip of cone and hollow it out.

Hmm... I think your original code structure is quite good already. You just need to modify it a little bit. The code structure could be as followed:

void drawCone(int width, int height) {
}

void drawBody(int width, int height) {
}

void drawRocket(int width, int height, int repeat) {
  while (repeat>0) {
    drawCone(width, height);  // draw the head
    drawBody(width, height);  // draw the body
    cout<<endl;  // separated each stage
    repeat--;
  }
}

int main() {
  // obtain user input for width, height, repeat
  // remember to validate all values to be valid before calling the drawing function

  // then call the drawing function using the values
  drawRocket(width, height, repeat);
  return 0;
}

The only problem you are having is how to draw it. For drawBody(), you just need to design how to draw the body (similar to your drawBox()) with its tail. For drawCone(), you may not use height if you want a fixed height cone. I added it just in case you want cone size to be width-height proportionate.

Your fixed height cone could be as followed:

void drawCone(int width) {
  // use cone height as 3, that means...
  //   the top row is either 1 or 2 stars depending on the width type
  //   the middle row size is around half size of the width
  //   the bottom row size is the width
  if (width>0 && (width%2)==0) {  // even width
    // implement it here
    // row #1
    for (int i=0; i<(width/2)-1; i++) { cout << " "; }
    cout << "**" << endl;
    // row #2
    // left side
    for (int i=0; i<(width/4); i++) { cout << " "; }
    // cone portion
    if ((width/2)%2!=0) {  // odd width of the half size
      for (int i=0; i<(width/2)+1; i++) { cout << "*"; }
    }
    else {
      for (int i=0; i<(width/2); i++) { cout << "*"; }
    }
    cout << endl;
    // row #3
    for (int i=0; i<width; i++) { cout << "*"; }
    cout << endl;
  }
  else if (width>0) {  // odd width
    // implement it similar to even type, but need to tweak it a bit
    // row #1
    for (int i=0; i<(width/2); i++) { cout << " "; }
      cout << "*" << endl;
    // row #2
    // left side
    for (int i=0; i<(width/4); i++) { cout << " "; }
    // cone portion
    if (((width-1)/2)%2!=0) {  // odd width of half size
      for (int i=0; i<(width/2)+2; i++) { cout << "*"; }
    }
    else {
      for (int i=0; i<(width/2)+1; i++) { cout << "*"; }
    }
    cout << endl;
    // row #3
    for (int i=0; i<width; i++) { cout << "*"; }
    cout << endl;
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.