4 Replies - 353 Views - Last Post: 25 October 2013 - 08:36 PM Rate Topic: -----

#1 michaelhammerjr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 30-August 13

help with empty cone

Posted 25 October 2013 - 04:40 PM

I am currently trying to make it so that this triangle/cone is empty on the inside and is not completed at the bottom. pretty much like this ^

int n;
	        
	        for(int i=1;i<=3;i++)
	        {
	              for(int sp=0; sp<=2-i; sp++)
                    {
                        cout << " ";
                    }
                for(int j=1;j<=2*i-1;j++)
                    cout<<"x";
                    cout<<"\n";


	        }


i have tried many different for loops and placement but my shape always comes out weird looking. some redirection of advice would be appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: help with empty cone

#2 Vaypur  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 52
  • Joined: 09-October 13

Re: help with empty cone

Posted 25 October 2013 - 06:40 PM

You are really close to getting it right. In your second for loop, consider counting backwards from your top # position. This way, it will move your #s one space back every loop. In your 3rd loop, you will need to fill out the right side of the pyramid. Since it is double side, set j<=i*2 and drop the -1. Print blanks inside your for loops. Print # just after your 2nd and 3rd for loop
for(){
blanks
}
cout << "#";


After you print your # sign for your 3rd for loop, end the line.

Let me know if you need any more assistance. I hope this helped steer you in the right direction.
Was This Post Helpful? 0
  • +
  • -

#3 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: help with empty cone

Posted 25 October 2013 - 06:44 PM

Put your code logic into the same (strict) order as your pattern:

1) You print 0 or more spaces first

2) You print the leftmost part of the triangle

3) You print a 1 or more spaces

4) Your print the rightmost part of the triangle

You need more logic inside the outermost for loop. It's a bit easier if you use r as the iterator for the outer for loop, and c as the iterator for the inner loops. r=row, c=column.
Was This Post Helpful? 0
  • +
  • -

#4 michaelhammerjr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 30-August 13

Re: help with empty cone

Posted 25 October 2013 - 07:58 PM

View PostVaypur, on 25 October 2013 - 06:40 PM, said:

You are really close to getting it right. In your second for loop, consider counting backwards from your top # position. This way, it will move your #s one space back every loop. In your 3rd loop, you will need to fill out the right side of the pyramid. Since it is double side, set j<=i*2 and drop the -1. Print blanks inside your for loops. Print # just after your 2nd and 3rd for loop
for(){
blanks
}
cout << "#";


After you print your # sign for your 3rd for loop, end the line.

Let me know if you need any more assistance. I hope this helped steer you in the right direction.

I am a little confused about what you mean by print blanks
Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1352
  • View blog
  • Posts: 4,654
  • Joined: 19-February 09

Re: help with empty cone

Posted 25 October 2013 - 08:36 PM

View Postmichaelhammerjr, on 26 October 2013 - 03:58 AM, said:

I am a little confused about what you mean by print blanks


I'm sure he means spaces.

You could use dashes (-) temporarily to analyze the problem :

2 rows uses 3 columns

-*-
*-*



3 rows uses 5 columns

--*--
-*-*-
*---*



4 rows uses 7 columns

---*---
--*-*--
-*---*-
*-----*

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1