4 Replies - 2660 Views - Last Post: 23 October 2009 - 05:59 PM Rate Topic: -----

#1 gbg24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-October 09

Draw Rocket

Post icon  Posted 23 October 2009 - 03:48 PM

Hello everybody,

I am working on a project for my class right now, but I am stuck. I am supposed to draw a rocket on the screen, using functional decomposition. The rocket is basically a cone, a variable number of rectangles, and another cone. The cone has to fit for all kinds of numbers. I got the part for the even numbers, but for the odd numbers it doesnt quite fit. I am supposed to have one star at the top (for the odd numbers) but I am having two. Here is the code for the odd numbers:
 { 
					 width=(width/2)+1;
					 int count,count1;
					 for (count=1; count<=width; count++)
					 {
						 for (count1=width-count; count1>=1; count1--)
						 { cout <<" "; }
						   cout <<"*";
						 for (count1=2; count1<=count*2-2; count1++)
						 {cout << " "; }
						 cout <<"*"<<endl;}
						 }



Any hint on how to get rid of that one star would be greatly appreciated.

This is what the rocket looks like for even numbers:

Enter width of the rocket: 6
Enter height of the rocket: 7
Enter how many stages you wish to display: 2
--*--*--
-*----*-
*------*
******
*------*
*------*
*------*
*------*
*------*
******
******
*------*
*------*
*------*
*------*
*------*
******
--*--*--
-*----*-
*------*
Press any key to continue . . .
Thank you. :) Have a great day.

Is This A Good Question/Topic? 0
  • +

Replies To: Draw Rocket

#2 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: Draw Rocket

Posted 23 October 2009 - 04:47 PM

Since you have two separate routines, even & odd, you could throw an if(row != first) on that first cout<<"*";.
Was This Post Helpful? 0
  • +
  • -

#3 gbg24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-October 09

Re: Draw Rocket

Posted 23 October 2009 - 05:00 PM

Thank you for your answer. I tried that, but it doesn't seem to work. Here is the entire function for the even/odd

void drawCone (int width, int stages) {
	 
	 if (width%2==0) {
					 width=width/2;
					 int count,count1;
					 for (count=1; count<=width; count++)
					 {
						 for (count1=width-count; count1>=1; count1--)
						 { cout <<" "; }
						 cout <<"*";
						 for (count1=2; count1<=count*2-1; count1++)
						 { cout << " "; }
						 cout <<"*"<<endl;}
						 }
					 
	 else 
					{ 
					 width=(width/2)+1;
					 int count,count1;
					 for (count=1; count<=width; count++)
					 {
						 for (count1=width-count; count1>=1; count1--)
						 { cout <<" "; }
						   cout <<"*";
											
						 for (count1=2; count1<=count*2-2; count1++)
						 {cout << " "; }
						 cout<< "*"<<endl;}
						 }
}



I know I have to do something to the very last 'for loop', but I'm not sure what. I tried different settings for the counters, but that doesnt work either. I'm a little confused. :blink:
Was This Post Helpful? 0
  • +
  • -

#4 brds  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 76
  • View blog
  • Posts: 515
  • Joined: 22-October 08

Re: Draw Rocket

Posted 23 October 2009 - 05:50 PM

Funny, when I put the if statement in I get
---*---
--*-*--
etc.
Was This Post Helpful? 0
  • +
  • -

#5 gbg24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-October 09

Re: Draw Rocket

Posted 23 October 2009 - 05:59 PM

:^: now I got it. :D I used the variable count1 instead of count.

Thank you for the help.

Have a nice evening.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1