Typos:
line 12 needs a semicolon
line 17 needs an open bracket
line 20 needs a == instead of =
line 23 needs an open bracket
line 30 needs an open bracket
Can't believe your compiler allowed any of that.
Logic:
You don't need your bool variable - you can remove it.
You don't need the j loop, you can remove that.
Test to see if your random number != new drawn number instead of equaling it.
If you can use ctime, you can have more random numbers, if not remove it, and the Srand line in main, and you will get the same random numbers every time
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
// The program draws 7 random "lottery"numbers in an array between 1 to 35.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{ int j=1;
srand(time(0));
int lotterynumber[7];
for(int i=0; i<7; i++){
lotterynumber[i]=rand()%35; // Randomizes a number between 1 and 35
if(lotterynumber[i]!=lotterynumber[j]) {
cout <<"Ticket #"<<j<<" "<< lotterynumber[i] << endl;
j++;}
}
return 0;
};
|