simple generating letters program

closed account (EAXiz8AR)
Ok so I'm trying to make a program that outputs 100 random lowercase letters in rows of 10. I got this far below, but the program keeps outputting only a bunch of ones or twos. Can you guys help me? thanks



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <cstdlib>
using namespace std;

void randomgen(char ch1, char ch2)
{
    for(int i = 1; i <= 100; i++)
    {
    cout << static_cast<char>('ch1' + rand() % ('ch2' - 'ch1' + 1));
    cout << " ";
        if (i % 10 == 0)
            {
            cout << endl;
            }
    }
}



int main()
{

char a, z;
randomgen(a, z);


return 0;

}
Last edited on
¿Do you understand the difference between a bottle and the beer that's inside?
1
2
char a, z; //these are variables, ¿what's their value? garbage
randomgen(a, z);


Do one thing and do it right.
char randomgen(char low, char high); //returns 1 random value between low and high
Then use that function in a loop.
Last edited on
Topic archived. No new replies allowed.