setw and while statements

This is a discussion on setw and while statements within the C++ Programming forums, part of the General Programming Boards category; Hey, I am doing a while statement where I am manipulating the outputs. My problem is I dont know how ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Unhappy setw and while statements

    Hey, I am doing a while statement where I am manipulating the outputs. My problem is I dont know how to manipulate each ouput.
    eg: int 1 = 0;

    while(i < 10 )

    {
    i = 1 + 2;
    cout << '\n' <<setw(3);
    cout<< '\n' <<setw(5);

    I want to display each output of "i"(2,4,6,8,10), using setw to manipulate the spacing and I dont know how. Thanx for your help.


    Tony.
    Last edited by taurusborn; 10-22-2001 at 06:55 AM.

  2. #2
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    What do you want the spacing to be? How are you trying to display your output? My best guess is that you want to display the output in a diagonal.

    Code:
    // don't forget this for setw()
    #include <iomanip.h>  // or <iomanip> if using namespace
    
    int main()
    {
        int i = 0;
    
        while ( i < 10 )
        {
            i+=2;
            cout << setw(i - 2) << i << endl;
        }
    
        return 0;
    }
    
    /*Output
    
    2
      4
        6
          8
            10
    */
    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    Talking Thanx

    Thanx, David for your help

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21