Please use code formatting, edit your post and add [code] and [/code] around your program.
And you can use [output][/output] for your example output instead of trying to align it with #.
if(base>3 && b!=z && a!=1 && a!=base && b==2+f && a==2+e)
There's no reason for this convoluted combination of conditionals.
Notice that whenever you print a '*', it is always followed by a '#' (space).
- First outer loop: print (2*n - 2) spaces. Then print 1 (* + space).
- Second outer loop: print (2*n - 4) spaces. Then print 2 (* + space).
- Third outer loop: print (2*n - 6) spaces. Then print 3 (* + space).
- (Do the outer loop n ('base') times)
- See the pattern?
int main()
{
int a;
int f;
int s;
int t;
int n;
cin>>n;
for(f=2*n-2;f>0;f--)
{
cout<<"#";
}
cout<<"*#"<<endl;
for(s=2*n-4;s>0;s--)
{
cout<<"#";
}
for(int i =2;i>0;i--)
{
cout<<"*#";
}
cout<<endl;
for(t=n;t>0;t--)
{
cout<<"*#";
}
}
Your first example, in my opinion, was closer. You need a nested for loop (for loop within a for loop).
- Each outer for loop handles printing each row
- Each inner for loop handles printing each character within a row
- Furthermore, the inner for loop can actually be two for loops; first, you print the appropriate amount of spaces. Then, you print the appropriate amount of "*#".