Printing values and their ascii symbol with for loops.

This is a discussion on Printing values and their ascii symbol with for loops. within the C++ Programming forums, part of the General Programming Boards category; Hi, Im trying to make a program that scans through the numbers 32-234 and then show both value and ascii ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    5

    Printing values and their ascii symbol with for loops.

    Hi, Im trying to make a program that scans through the numbers 32-234 and then show both value and ascii symbol.
    The result must be presented in several columns and not in rows.

    32 33 ! 34 " wrong.

    32
    33 !
    34 " right.

    Im having problems with the nested for-loops.

    this is how I run through 32-234 and present it the wrong way:

    Code:
    for(int i = 32; i <= 234; i++)             {
                    ch = static_cast<int>(i);
                    cout << setw(4) << i  << setw(4) << ch;                
                }

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    5
    My question is how to set up the for loops.

    The outer loop runs the rows, inner the columns.

    1st loot checks the value and ascii symbol

    2nd checks the rows

    3rd checks the colums

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    As far as I can tell you don't need a second loop. You need to output a linebreak ( std::cout << std::endl; ) after your text so the next will appear in another line.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    101
    The following will do it for you....

    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    int main()
    {
        system ("Color f9");
        HANDLE hOut;
    
        int i;
        int x=0;
        int y=10;
    
        COORD Position;
        hOut=GetStdHandle (STD_OUTPUT_HANDLE);
    
        for (i=32;i<=255; i++)
        {
            Position.X=x;
            Position.Y=y;
            SetConsoleCursorPosition(hOut,Position);
            cout.width(3);
            cout << i << "  " << (unsigned char)i << flush;
            ++y;
            if(y>38)
            {
                y=10;
                x+=10;
            }
       }
    
       cout<<endl<<endl<<endl<<endl<<endl<<endl;
    
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ascii values
    By caliber005 in forum C Programming
    Replies: 6
    Last Post: 05-18-2011, 03:16 PM
  2. ASCII values help
    By Grant_Searle in forum C Programming
    Replies: 5
    Last Post: 10-22-2010, 09:01 AM
  3. Using ASCII Values
    By ga836044 in forum C Programming
    Replies: 7
    Last Post: 03-17-2004, 12:31 AM
  4. adding ASCII values
    By watshamacalit in forum C Programming
    Replies: 1
    Last Post: 12-26-2002, 06:16 PM
  5. printing ASCII
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-10-2002, 09:13 PM

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