Lottery program not working

Hello!
I've been trying to get this lottery program to work for most of the day now, and i can't for the life of me figure out why nothing comes up in the cmd window when it runs.
If anyone could enlighten me on what i might be overlooking, i'd be very grateful.

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;

int main()
{
    int lotteryNumber[7]; 
    bool similar=false;

    for(int i=1; i<7; i++)
    {
        lotteryNumber[i]=rand() % 35 + 1; 

        for(int j=1; j<i; j++) 
            if(lotteryNumber[i]==lotteryNumber[j])
                similar=true;

        if
            ((similar=i--))  
            similar=false;

        else 
            cout << lotteryNumber[i] << endl;
    }

    return 0;
}
You never seed the random number generator.
The error is probably:
(similar=i-1)
which should be:
similar == i-1

But, probably, what you actually wanted is this:
https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
Oh, now i feel rather stupid. The program is atleast showing some numbers now, but only 5 out of the 7 it's intended to..
But thanks for the help!
1
2
3
4
5
6
7
        if (similar)
        {
            --i;
            similar=false;
        }
        else 
            cout << lotteryNumber[i] << endl;


Not a fan of modifying for loop counters inside the body of the loop.
Topic archived. No new replies allowed.