Generating Random Letters

My problem says:
Have the user enter a number from 1-80 then print out a string of random letters(a to z lowercase) of that length.

I have been able to enter the number and output the correct amount of letters but i can't figure out how to get them to be in a random order and not in alphabetical. Help! Here is what I have so far.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{
	int i=0;
	int num;

	cout<<"How many letters do yu want in your random string?";
		cin>>num;
	char alpha[80]= {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	

	for (i=0; i<=num; i++)
		cout<<alpha[i];


	cout<<"\n\n";

	system ("pause");
}
14
15
16
17
18
19
20
21
22
    char c;
    int r;

    srand (time(NULL));    // initialize the random number generator
    for (i=0; i<num; i++)
    {    r = rand() % 26;   // generate a random number
          c = 'a' + r;            // Convert to a character from a-z
          cout << c;
    }


You don't need the alpha array at all.

Line 14: The termination condition of your for loop is incorrect.

Topic archived. No new replies allowed.