Thread: Trying All Possibility's

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    208

    Trying All Possibility's

    In a C++ book I am reading it says to use nested for() loops to create a program that prints every ASCII character to the screen then does the same thing using two digits printing every possible combination i.e. a b c
    aa ab ac ba bb bc ca cb cc
    etc.

    it works fine but sometimes I get the odd out of place character over about 10 spaces from everything else. I dunno if this matters but I was wondering if anyone knew why this was happening

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    void two();
    
    int main()
    {  for(int i=1; i<255; i++)
       { cout<<"\n" << (char)i;
       }
       cout<<"\n\n";
       system("PAUSE");
       two();
       cout<<"\n\n";
          system("PAUSE");
          return 0;
    }
    
    void two()
    { cout<<"\n\n*******************************************";
       for(int a=1; a<255; a++)
       {
         for(int k=1; k<255; k++)
         {cout<<"\n";
          cout<<(char)k;
          cout<<(char)a;
         }
       }
    }

  2. #2
    Registered User raimo's Avatar
    Join Date
    Jun 2002
    Posts
    107
    I guess you knew that tab('\t') and newline('\n') and many more are ascii characters and how they are usually presented?

    And is you purpose to print characters 1..254 like you are doing? There are two more ascii characters, like 0 and 255.

Popular pages Recent additions subscribe to a feed