Issue in For loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samimmu
    New Member
    • Mar 2007
    • 32

    Issue in For loop

    Code:
    #include <iostream>
    #include <iostream>
    #include <string>
    #include<cctype>
    
    using namespace std;
    int main()
    {
        int i,j,k;
        
     
                         
        for(i=0; i<8; i++)
        {
           for(j=0;j<i;j++)
            {
                cout<<'\t'<<"*";
            
                 }
                              
               for(k=0;k < 16; k= k+2){
            cout<<endl;
           
       }
    }
     for(i=7; i>=0; i--)
        {
            for(j=i;j>=0;j--)
            {
                cout <<'\t'<<"*";
            
                 }
                              
               for(k=14;k >0; k= k-2){
            cout<<endl;
           
        }
    }
        system("PAUSE");
        return 0;
    }
    please guys, i have done that loop and i want the ouput to look like this
    *
    * *
    * * *
    * *
    *
    i want the first star to be in the middle and then in the second row two stare also in the middle uder the first star which means the first star look in between then ... i hope u can help me guys
  • scruggsy
    New Member
    • Mar 2007
    • 147

    #2
    Originally posted by samimmu
    please guys, i have done that loop and i want the ouput to look like this
    *
    * *
    * * *
    * *
    *
    Is that really how you want it to look, or do you want it to look like this:
    Code:
    .
        *
       * *
      * * *
       * *
        *
    ...or something along those lines?

    If so, you will need to output enough whitespace before each set of stars in order make them line up. You should be able to calculate the number of tabs or spaces to use based on the value of the loop variable: more spaces for lower values, fewer spaces for higher values.

    Comment

    • samimmu
      New Member
      • Mar 2007
      • 32

      #3
      Originally posted by scruggsy
      Is that really how you want it to look, or do you want it to look like this:
      Code:
      .
          *
         * *
        * * *
         * *
          *
      ...or something along those lines?

      If so, you will need to output enough whitespace before each set of stars in order make them line up. You should be able to calculate the number of tabs or spaces to use based on the value of the loop variable: more spaces for lower values, fewer spaces for higher values.

      yeah exactly as you said. i should output like the way you said.... i wish i can help by writing up on that code...

      Comment

      • scruggsy
        New Member
        • Mar 2007
        • 147

        #4
        Originally posted by samimmu
        yeah exactly as you said. i should output like the way you said.... i wish i can help by writing up on that code...
        Yeah, no one will write the code for you.
        But if you post your code and explain the problem we can help you figure out how to get it working.

        Comment

        Working...