pyramid w/ imputted base length

Feb 12, 2011 at 8:49pm
hi guys, i need help writing a code to produce a pyramid of *'s. the user needs to imput the base lenght and the pyramid should then form with the base number of *'s being the number imputted. the product should look like this;

Enter base #; 9



....*
...***
..*****
.*******
*********
(periods are to show what kind of pyramid i need to form)

the code should only use
#inclue<iostream>
using namespace std
&
int main()

someone please help with the code for this, thanks!
Feb 12, 2011 at 8:57pm
Where do all these "pyramid of *" questions keep coming from? Is there some class somewhere that repeats the same question every fortnight?
Feb 12, 2011 at 8:59pm
closed account (1yR4jE8b)
It's a very common first year comp-sci assignment question.
Feb 12, 2011 at 9:01pm
From what I can tell, the number of spaces for the first asterisk can be determined with the formula (n-1)/2 where n is the base #. Then, every subsequent line has 1 less space before the first asterisk.
Feb 12, 2011 at 9:03pm
closed account (3hM2Nwbp)
I would think that campuses would have a course before C++ in dealing with pseudo-code. The campus that I attended had "Object Oriented Analysis & Problem Solving" which dealt with the simple control structures.

Neverknownig - work out the pseudo-code before trying to write it in C++ and post what you come up with.
Feb 13, 2011 at 3:39am
so can anyone help me with the code for this or no?
Feb 13, 2011 at 5:00am
No one here will do your homework for you. The best we'll do is give you helpful hints.

Use the formula numspaces=(n-1)/2 to determine the number of spaces before the first asterisk, use cout<<"this is a string" to output stuff to the console, and use a for loop to create the pyramid. I can't really say much more without doing it for you =\
Feb 13, 2011 at 7:14pm
yeah, this is for my dad. not homework. thanks though.
Feb 13, 2011 at 7:17pm
neverknownig wrote:
this is for my dad. not homework.

I have a hard time believing that.
Feb 13, 2011 at 7:56pm
How about some pseudo code?

1
2
3
4
5
6
7
8
9
10
var base
var space
var line
input base
space=(base-1)/2
while line is less than or equal to base
	output ' ' space times
	output '*' line times
	space=space-1
	line=line+1
Topic archived. No new replies allowed.