Double Triangle problem

Hi everyone!
i wrote code for printing a double triangle. Its woking fine upto input is 7. but when the input is 8 the output is disturbed. can any one suggest me a solution? the code is this.


#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"Enter a number"<<endl;
cin>>a;
int stars=1;
int stars1=1;
for(int i=0 ; i<a ; i++)
{
for(int j=0 ; j<stars1 ; j++)
cout<<"*";
stars1++;

cout<<"\t\t";

for(int j=0 ; j<stars ; j++)
cout<<"*";
stars++;

cout<<endl;
}

system("pause");
return 0;
}


A tab is 8 spaces.
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
#include <iostream>
using namespace std;

int main()
{
    int a;
    cout<<"Enter a number"<<endl;
    cin>>a;

    int stars=1;
    int stars1=1;
    for(int i=0 ; i<a ; i++)
    {
        for(int j=0 ; j<stars1 ; j++)
            cout<<"*";
        stars1++;

        //cout<<"\t\t"; // *** replaced this

        const int TABSZ = 8 ; // *** with this
        const int NSPACES = ( a/TABSZ + 1 ) * TABSZ - i ; // *** this
        for( int t = 0 ; t < NSPACES ; ++t ) cout << ' ' ; // *** and this

        for(int j=0 ; j<stars ; j++)
            cout<<"*";
        stars++;

        cout<<endl;
    }
}
thanks man... (y)
Topic archived. No new replies allowed.