Need help with making a random word genereting program

Hi,
I'm making a program which will generate random words and the words shouldn't repeat. I'm new in programming and I would like to get some help :)

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
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>

using namespace std;


int main()
{
    int word[4];
    srand(time(0));
    for(int x = 0; x<5; x++){
    word[x] = 1+rand()%5;

    if(word[x]==1){
            cout<<"sky"<<endl;
        }
    if(word[x]==2){
            cout<<"tree"<<endl;
        }
    if(word[x]==3){
            cout<<"house"<<endl;
        }
    if(word[x]==4){
            cout<<"car"<<endl;
        }
    if(word[x]==5){
            cout<<"speed"<<endl;
        }
    
    }
    return 0;
}


Soo how I can make conditions for the words.
(example: The program can repeat the word "speed" maximum 2 times, so the words can't be : 1-car 2-speed 3-tree 4-speed 5-speed etc..)
Last edited on
You can create an array which stores the number of time each word appears.
Do as KMagic said. Don't forget to check whether a word has been called twice.
Can anyone give me an example, please ?
Topic archived. No new replies allowed.