0

I am having a problem ending a line after a certain amount of characters. Also I would like not have the second occurrence when I print thing out.

For instance it would show
The first problem

Instead of: KTAKSFJKLAHGLASLDKAJGDKJ

I prefer :
KTAKSFJK
LAHGLASL
DKAJGDKJ

The second problem:

KTTT

K = 1
T = 3
T = 3
T = 3

If anyone knows how to delete the other two I would appreciate.

//Generate Characters
int generateChar( int genChar[], int seed, int numOfChar )
{
    srand(seed);
    for ( int index = 0; index < numOfChar; index++ )
    {
        genChar[index] = (rand() % 25 + 65);
        
        cout << (char)genChar[index];
    }
         cout << endl;
}

//Count numbers
int count( int genChar[], int seed, int numOfChar)
{
    int counter = 0, temp, ascii = 65 ;
    for (int index = 0; index < numOfChar; index++)
    {
        
        temp = genChar[index];
        
        for (int k = 0; k < numOfChar; k++)
        {
           
            if (temp == genChar[k]) { counter++; }
            
        }
        cout << (char)genChar[index] << " = " << counter << endl;
        counter = 0;
        temp = genChar[index];
        
        }  
    
}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by WaltP
0

1) count the number of characters and when you hit your magic number output a \n
2) call srand() only at the beginning of your program, never in your function

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.