how to make a prymaid in c++?

Oct 14, 2012 at 1:05pm
Right now this is what i have but with numbers(look at seed1)

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

and i want this program to output something in this pyramid/christmas tree format(no "s") but with numbers i am giving.

sssssss******
ssssss********
sssss**********
ssss************
sss**************
ss****************
s******************
********************

and oh yeah i know i will need int space; maybe int rows; too so please tell me how i can do that, i have hard time understanding in class because english is not my first language.


The following is my code, its fully working.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
using namespace std;

void input(int &height, int &seed1){

    cout<<"Your first num:";
    cin>>seed1;

    cout<<"Your height: ";
    cin>>height;


}

void output (int height, int seed1){

    int n;
    int n1;
    int n2;

    for(n=0; n<height; n++){

    for (n1=0; n1<=n; n1++){
        if (seed1>=10){
            seed1=seed1-10;
        }
        cout<<seed1;
        seed1++;
    }




    cout<<endl;



}


}
int main(){
int height;
int seed1;
input(height,seed1);
output(height,seed1);

return 0;
}
Oct 14, 2012 at 3:23pm
See

cout::setw(int). This function fills space.

So those "s" characters you are using would be the values of the argument that you would pass to setw(int).
Last edited on Oct 14, 2012 at 3:26pm
Oct 14, 2012 at 3:38pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void output (int height, int seed1)
{

    int n;
    int n1;
    int n2;

    for(n=0; n<height; n++)
    {
        for (int k=0; k<(height-n)/2; ++k)
        {
            cout << ' ';
        }

        for (n1=0; n1<=n; n1++)
        {
            if (seed1 >= 10){
                seed1 = seed1-10;
            }
            cout<<seed1;
            seed1++;
        }

        cout<<endl;
    }
}
Topic archived. No new replies allowed.