Columns in a console out...

This is a discussion on Columns in a console out... within the C++ Programming forums, part of the General Programming Boards category; Hey Guys, Newbie here. I have written a little program as specified by our teacher. I just need to know ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Question Columns in a console out...

    Hey Guys,

    Newbie here. I have written a little program as specified by our teacher. I just need to know how to get it into columns of 10. I tried with a for loop and modulus, but it only spaces them and doesn't do it vertically.
    Thanks for any suggestions.
    Code:
    double alpha[50];
    int i,a;
    int main(int argc, char *argv[])
    {
        
        for (i =0; i < 25; i++)
        {
              alpha[i]=i*i;  
                    cout << alpha[i] << endl;
            }
         for (a=0; a < 50; a ++)
           {
              
                    alpha[a]=a*3;
            cout << alpha[a]<<endl;
          }

    Thanks again,
    -Scott

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,616
    For starters, you should indent your code properly, declaring variables near first use, e.g.,
    Code:
    #include <iostream>
    
    int main()
    {
        using namespace std;
        double alpha[50];
    
        for (int i = 0; i < 25; ++i)
        {
            alpha[i] = i * i;
            cout << alpha[i] << endl;
        }
    
        for (int a = 0; a < 50; ++a)
        {
            alpha[a] = a * 3;
            cout << alpha[a]<<endl;
        }
    }
    Next, in a new program, create an array of 100 integers, from 0 to 99. Then, use your modulus idea to print them out in columns of 10. After you have done this, apply what you have discovered to your current program.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Thank you.

    Thank you for the reply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i need help with this question:
    By marcuspax in forum C Programming
    Replies: 16
    Last Post: 08-16-2010, 08:12 AM
  2. Nintendo 3DS
    By Cheeze-It in forum General Discussions
    Replies: 30
    Last Post: 03-27-2010, 02:32 AM
  3. Full Screen Console
    By St0rmTroop3er in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2005, 09:59 PM
  4. Console Functions Help
    By Artist_of_dream in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 02:44 AM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 09:19 AM

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