Nov 3, 2014 at 2:59am UTC
Write a lottery program that generate 5 random numbers from 1-20 inclusive.
I had the whole things but it still giving me error. I am stuck.
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
#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);
}
}
Last edited on Nov 3, 2014 at 3:01am UTC
Nov 3, 2014 at 9:03am UTC
for (int i = 0; i < 5; i++);
yikes, that semi-colon. That's pretty common mistake though. :)
i = lottery[5]; //semi-colon
My advice: Always check for the semi-colons. They're pretty nasty. heh
Last edited on Nov 3, 2014 at 9:06am UTC
Nov 4, 2014 at 4:32am UTC
I add the semi colon but then it said my lottery[i] is unidentified identifier.
Nov 4, 2014 at 6:36am UTC
Huh? That's weird. I don't see any problem compiling here(Was it still the code above? :)). Btw, if you really want to be sure, try changing variable i to something else, because 'i' think that would be redundant.