Help making a simple newb prog look nice

This is a discussion on Help making a simple newb prog look nice within the C++ Programming forums, part of the General Programming Boards category; Im wondering how to make this simple program look a bit more organized, say by listing 10 ASCII chars per ...

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

    Question Help making a simple newb prog look nice

    Im wondering how to make this simple program look a bit more organized, say by listing 10 ASCII chars per line rather than just going on and on like it currently is. Here is the code for it, compile it and you'll see what i mean.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    did you forget something??
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    5

    Talking Oops hehe...

    Hehe forgot the code...


    #include "stdafx.h"
    #include <iostream.h>

    int main()
    {
    for(int x=0; x<256; x++)
    {
    cout<<x<<". "<<(char)x<<" ";

    }
    return 0;
    }

  4. #4
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    See if this works:

    #include "stdafx.h"
    #include <iostream.h>

    int main()
    {
    int y = 0;
    for(int x=0; x<256; x++)
    {
    if(y > 9)
    {
    y = 0;
    cout<<"\n";
    }
    cout<<x<<". "<<(char)x<<" ";
    y++;
    }
    return 0;
    }
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    easier than that. Use modulus operator.

    Code:
    #include "stdafx.h" 
    #include <iostream.h> 
    
    int main() 
    { 
    for(int x=0; x<256; x++) 
    { 
    cout<<x<<". "<<(char)x<<" "; 
    if (x%10==0) cout<<endl;
    } 
    return 0; 
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    5

    ty

    it works now.

  7. #7
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    whats with stdafx.h?

  8. #8
    Registered User
    Join Date
    Nov 2001
    Posts
    30
    >easier than that. Use modulus operator.

    ...pot heads, such slackers....why make it so easy all the time? You could do something like this

    >#include "stdafx.h"
    >#include <iostream.h>

    >int main()
    >{

    double i;

    >for(int x=0; x<256; x++)
    >{
    >cout<<x<<". "<<(char)x<<" ";

    i = double(x)/10.0;
    for(int j=1; j<256/10+1; j++) if(i == j) {cout << endl; break;}

    >}
    >return 0;
    >}

    better yet, replace the extremely efficient for loop stated above by yours truly, with if(i == 1 || i == 2 || i == 3 || i == 4|| i == 5 || i == 6 || i == 7 || i == 8 || i == 9 || i == 10 || i == 11 || i == 12 || i == 13 || i == 14 || i == 15 || i == 16 || i == 17 || i == 18 || i == 19 || i == 20 || i == 21 i == 22 || i == 23 || i == 24 || i == 25) cout << endl;

    now that is clean code, and none of that slacker bs to be found

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  3. Replies: 2
    Last Post: 01-13-2003, 12:28 PM
  4. A nice, simple question
    By Kyoto Oshiro in forum C++ Programming
    Replies: 4
    Last Post: 07-08-2002, 10:05 PM
  5. best prog for making animated gifs?
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-23-2001, 04:49 PM

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