#include<iostream>
usingnamespace std;
int lotteryList[i];
int main()
{
constint 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;
}elseif(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 :)
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.
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.
@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 ?