making a rhombus with just for loop

I have just started programming in C++, and in our class we started with for loops today, I was just trying to make a rhombus in cpp which will take an input of length of a side of a hombus and display on screen.

I am using devc++ complier http://www.bloodshed.net/devcpp.html
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
#include <iostream.h>
#include<conio.h>
main()
{
      int i,l,n,k,m;
      cout<<"Please Enter Number of Lines :";
      cin>>n;
      m=(((n-1)*2)-1);
      for (k=1;k<=n;k++)//Print Top Star
      cout<<" ";
      cout<<"*";
      cout<<"\n";
      for (i=1;i<=(n-1);i++)//Print Upper Half
      {
          for((k=(n-i));k>1;k--)
          cout<<" ";
          cout<<" *";
          for (l=1;l<=((i*2)-1);l++)
          {
           cout<<" ";
          }
         cout<<"* ";
         cout<<"\n";
      }
      for (i=2;i<=(n-1);i++)//Print Lower Half
      {
          for(k=0;k<=(i-1);k++)
          {
               cout<<" ";
          
          }
          cout<<"* ";
          for (l=(m-4);l>=1;)
          {
           cout<<" ";
           l=l-1;
          }
          m=m-2;
         cout<<" *";
         cout<<"\n";
      }
      for (k=1;k<=n;k++)//Print Bottom Star
      cout<<" ";
      cout<<"*";

getch();
}          


Its showing well and good for upper half but lower half second last line is messed up.
Can anybody help fixing the program ?
Last edited on
Ran your code, it runs correctly for me. Built it with VS2015 and GCC 4.9. It's fine.
have u checked the second last line ?
Topic archived. No new replies allowed.