code compile error

hi, need help running this code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
using namespace std;
int lotteryList[i];
int main()
{
const int LOTTERY = 10;
int nums [LOTTERY] = {13579, 26791, 26792,33445, 55555, 62483, 77777, 79422, 85647, 93121 };

//get winning number
int winningNumber;
cout<<"Enter this week’s winning number";
cin>>winningNumber;
for(int i=0;i<10;i++)
{
if(lotteryList[i]==winningNumber)
{
cout<<"One of the tickets is a winner this week."<<endl;
break;
}else if(i==9) cout<<"Not one of the tickets is a winner this week."<<endl;
}
system("pause");
return 0;
}


here are the following errors while compiling:
1>------ Build started: Project: project4, Configuration: Debug Win32 ------
1> project4.cpp
1>c:\users\cathy\documents\visual studio 2010\projects\project4\project4\project4.cpp(4): error C2065: 'i' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

this will be my lucky lottery if you help me fix this :)
Move above the for loop your int I
And then just in the for loop put I=0.

This is because I ==9 does not see the type for I.
Last edited on
Line 3: int lotteryList[i]
This does not specify a size for the array. Change "i" to 10 (as 10 is the size you're using elsewhere in your program), and it should get rid of that error.
in line 15 you're checking for lotterylist[i]==winningnumber;
But the array that you have initialized for the numbers is on line 7"num[lottery]".

so, check for num[lottery]==winningnumber
dhruv90 - num[LOTTERY] is the equivalent of num[10]. Not only would that be useless (checking the same index 10 times, as per the for loop), but that index (10) is beyond the boundaries of the array, which has 10 elements. 10 is not the index of any of its elements; a 10-element array's elements have indices 0-9. The compiler will accept your suggestion, but running that code will result in a segmentation fault.
sorry, wat i meant was check for num[i] in the for loop and not lotterylist[i], cause he has initialized the num[].
@trojansdestroy, so i have fixed i to 10. this time the program compiles and runs in the console but when I put the winning numbers, it shows the following output "Not one of the tickets is a winner this week." How do i fix that ?
nevermind i got it up and running.. thanks guys :)
Topic archived. No new replies allowed.