Random Word Generating

Sups :3
So I'm trying to generate a random word though i'm having some issues with it at the moment. I'm using random numbers to them making them.
Here is an example of how i'm trying to do this though its not working.


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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>
#include <direct.h>
#include <fstream>
using namespace std;

int main()
{
int randomnumber;
char randomword;

srand(time(NULL));

for (int loop = 0; loop <= 5; loop++;)
{

randomnumber = rand() % 5;

if (randomnumber == 1)
{
    randomnumber = 0;
    randomword + 'a';
}
if (randomnumber == 2)
{
    randomnumber = 0;
    randomword + 'b';
}
if (randomnumber == 3)
{
    randomnumber = 0;
    randomword + 'c';
}
if (randomnumber == 4)
{
    randomnumber = 0;
    randomword + 'd';
}
if (randomnumber == 4)
{
    randomnumber = 0;
    randomword + 'e';
}
if (randomnumber == 5)
{
    randomnumber = 0;
    randomword + 'f';
}

}

cout << randomword;
return 0;
}


I know i'm probably missing something really obvious or stupid.
Thanks
randomnumber = rand() % 5; doesnt have value 5.

Ex: 5005 % 5 = 0
at the begining of the loop add

1
2
randomnumber = rand() * 57;
randomnumber = rand() % 5;


otherwise everytime your loop runs it will generate the same letter. If you multiply your rand() by 57 or any other integer other than 1 or 2, you will take the amount of seconds from your

srand(time(NULL));

multiply it by 57 then take the modulus of 5 (which will give you a number 0-4 so i suggest doing (rand() % 5)+1 so it doesnt give you a value of 0 & also take out randomnumber = 0). Now the second time the loop runs you will have a value between 1 and 5. It will take that number and multiply it by 57 then mod 5.

ex.

loop runs once and your number is 3 so it generates a 'c'

second time through you take number * 57 and generate a larger integer and then take % 5 of that integer
Uhm I'm a bit confused do you think you could give me an example of what you mean?
Topic archived. No new replies allowed.