CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    1

    Angry Need help with short program!!!

    Hi,
    I need help building a program that is supposed to come out looking like this using nested for loops. Cans someone please help!

    1
    12
    123
    1234
    4321
    _ 321
    __ 21
    ___ 1

    Those are spaces in the bottom 3

    I currently have this coming out:

    1
    12
    123
    1234
    1234
    4321
    4321
    32
    21
    1

    with this coding:
    #include <iostream>
    using namespace std;
    int main(){

    for (int i=1; i<5; i++)
    {
    cout<<i;
    cout<<"\n";
    for (int j=1; j<i+1; j++)
    {
    cout<<j;
    }
    }
    cout<<"\n";
    for (int n=4; n>=1; --n)
    {
    cout<<n;
    cout<<"\n";
    for (int m = 4; m>=n; m--)
    {
    cout<<m;
    }
    }
    return 0;
    }

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Need help with short program!!!

    Welcome to Codeguru.

    Next time when you are posting pieces of code, use these

    Code:
    cout<<m;
    Convert 'm' to a string (you can use sprintf (%d)). Before outputting the 'm'-string write the missing '_' chars according to the length of the 'm'-string.

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Need help with short program!!!

    Well, you missed to output first some spaces (m-n).
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured