Need ASAP help with array in C++
Nov 4, 2014 at 4:40am UTC
I need to write a lottery program that generate 5 non duplicate number between 1-20. Below is my code and it said my [i] is undefined and it is an undeclare identifier. Need help on this asap.
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
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;
int main()
{
srand(time(NULL));
int lottery[5] = { 0, 0, 0, 0, 0 }, count = 0, rand_lottery;
bool isdup = false ;
cout << "Your Lottery:" << endl;
while (count < 5)
{
int rand_lottery, i;
rand_lottery = rand()%20 +1;
i = lottery[5];
for (int i = 0; i < 5; i++);
{
if (lottery[i] == rand_lottery)
{
isdup = true ;
}
}
if (isdup == false )
{
lottery[count] = rand_lottery;
count++;
}
}
for (int i = 0; i < 5; i++);
{
cout << lottery[i] << " " ;
return (0);
}
}
Nov 4, 2014 at 6:16am UTC
for (int i = 0; i < 5; i++);
try getting rid of this semi-colon..see if it works. :)
Topic archived. No new replies allowed.