Program that diplays corresponding ASCII code for the numbers 0-127, 16 per line.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nothingfights
    New Member
    • Apr 2008
    • 17

    #1

    Program that diplays corresponding ASCII code for the numbers 0-127, 16 per line.

    this continue to stop at 10 and 13. Need Help!
    Code:
    # include <iostream>
    using namespace std;
    
    int main()
    {
     char k;
     for(int i=0; i<127; i++)
    {
    cout << (char)i;
    k= (i+1)%16;
    if (k == 0)
    cout << "\n";
    
    }
     cout << "\n";
    	return 0;
    	}
  • nothingfights
    New Member
    • Apr 2008
    • 17

    #2
    This is the output that it gives.
    ☺☻♥♦♣
    ♫☼
    ►◄↕‼¶§▬↨↑↓→←∟↔▲ ▼
    !"#$%&'()*+,-./
    0123456789:;<=> ?
    @ABCDEFGHIJKLMN O
    PQRSTUVWXYZ[\]^_
    `abcdefghijklmn o
    pqrstuvwxyz{|}~

    Comment

    • Laharl
      Recognized Expert Contributor
      • Sep 2007
      • 849

      #3
      Please only create one thread per problem. If you're having issues with getting responses, post in the thread yourself (after a day or so with no help) rather than creating a new one. To answer your question, are you familiar with if statements?

      Comment

      • nothingfights
        New Member
        • Apr 2008
        • 17

        #4
        yes i am famililar with if statements

        Comment

        • nothingfights
          New Member
          • Apr 2008
          • 17

          #5
          i would like to know why it stops at 10 and 13

          Comment

          • Laharl
            Recognized Expert Contributor
            • Sep 2007
            • 849

            #6
            It stops at 10 and 13 because those are LF and CR (line feed and carriage return). These are printed as newlines because in files, rather than using the \n newline character, OSs use LF+CR or CR to mark the end of a line. For more information, Wikipedia. Thus, if you want 16 characters per line, you'll need to replace printing these with printing some other form of whitespace.

            Comment

            Working...