Thread: Please Help!!

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    15

    Please Help!!

    The program gives gives me this output:

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

    Can anyone tell me PLEASE how to, instead, get the blank spaces first instead at the end. In other words, the second line would have 1 blank space followed by 4 stars, third line would have 2 blank spaces followed by 3 stars, and so on. So that the vertical line (with 5 stars) appears at the end rather than at the beginning.
    I will really appreciate it a lot. Thanks a million in advance.
    Arooj

    void main()
    {
    clrscr();

    for (int i = 1; i <= 5; i++) {

    for (int j = 5; j >= i; j--)
    cout << " *" ;
    cout << endl;
    }

    getch();
    }
    Last edited by Arooj; 02-28-2003 at 12:49 AM.

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    a) Don't use void main(), use int main()
    b) Don't use getch(), use cin.get()
    c) Don't use Depricated headers like <iostream.h>

    Code:
    #include <iostream>
    
    int main()
    {
       for (int i = 5; i >= 1; --i)
          for (int j = i; j > 0; --j)
             std::cout << '*' << std::endl;
    
       return 0;
    }
    Edit: He edited his post, it's now much different than the one I replied to.
    Last edited by Eibro; 02-28-2003 at 01:10 AM.

  3. #3
    Registered User kiss_psycho's Avatar
    Join Date
    Feb 2003
    Posts
    49
    This is what u want..
    and yes, cin.get() does not work as getch() does.

    Code:
    #include<iostream.h>
    
    int main()
    {
            int i,j;
    
    	for(i=1;i<=10;i++)
    	{
    		for(j=1;j<=i;j++)
    			cout<<" ";
    		for(j=1;j<=(10-i);j++)
    			cout<<"*";
    		cout<<endl;
    	}
    
            return 0;
    }
    Last edited by kiss_psycho; 02-28-2003 at 01:06 AM.
    Definition of Programmer : A red-eyed mumbling mammal capable of conversing with inanimate objects.

    Happy Hunting...
    The Root

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    15
    Thanks both of you very much. However, after posting the question I tried very hard and came up with this which also worked. But your codes were better.

    #include <iostream.h>
    #include <conio.h>

    void main()
    {
    clrscr();
    int length;
    cout << "Enter length: ";
    cin >> length;
    cout << endl;
    for (int i = 1; i <= length; i++) {

    for (int k = 2; k <= i; k++ )
    cout << " ";

    for (int j = length; j >= i; j--)//{
    cout << " *" ;
    cout << endl;

    }

    getch();

    }
    arj

  5. #5
    Registered User kiss_psycho's Avatar
    Join Date
    Feb 2003
    Posts
    49
    use code tags while posting code, man. neway glad it worked.
    Definition of Programmer : A red-eyed mumbling mammal capable of conversing with inanimate objects.

    Happy Hunting...
    The Root

Popular pages Recent additions subscribe to a feed