I have the following program which was a vector. I have done some conversions so it has the following array code.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
//This program calculates whether or not a person's lottery numbers are the winning numbers.
#include<iostream>
#include <fstream>
using namespace std;
void ticketSort(LOTTERY);
bool search(LOTTERY);
int main()
{
ofstream output;
const int LOTTERY = 10;
//Opens the txt file
output.open("C:\\CS140\\Spring2013\\lotto.txt");
//Store values in the array.
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;
//Sort ticket
ticketSort(LOTTERY);
//Check if win
if(search(LOTTERY,winningNumber))
output<<"One of the tickets is a winner this week."<<endl;
else
output<<"Not one of the tickets is a winner this week."<<endl;
//Closes and saves the txt file
output.close();
system("pause");
return 0;
}
void ticketSort(LOTTERY ticket)
{
int size=ticket.size();
int startScan,minIndex,tempTicket,minTicket;
for(startScan=0;startScan<(size-1);startScan++)
{
minIndex=startScan;
minTicket=ticket[startScan];
for(int index = startScan+1;index<size;index++)
{
if(minTicket>ticket[index])
{
minTicket=ticket[index];
minIndex=index;
}
ticket[minIndex]=ticket[startScan];
ticket[startScan]=minTicket;
}
}
}
bool search(LOTTERY list,int winNumber)
{
bool found=false;
int first=0,
last=list.size()-1,
middle;
while(!found&&first<=last)
{
middle=(first+last)/2;
if(list[middle]==winNumber) found=true;
else if(list[middle]>winNumber) last=middle-1;
else first=middle+1;
}
return found;
}
|
After running, I have the following error(s).
Error 1 error C2065: 'LOTTERY' : undeclared identifier c:\temp\ken\project4\learning.cpp 6 1 project4
Error 2 error C2182: 'ticketSort' : illegal use of type 'void' c:\temp\ken\project4\learning.cpp 6 1 project4
Error 3 error C2065: 'LOTTERY' : undeclared identifier c:\temp\ken\project4\learning.cpp 7 1 project4
Error 4 error C2064: term does not evaluate to a function taking 1 arguments c:\temp\ken\project4\learning.cpp 27 1 project4
Error 5 error C2064: term does not evaluate to a function taking 2 arguments c:\temp\ken\project4\learning.cpp 30 1 project4
Error 6 error C2065: 'LOTTERY' : undeclared identifier c:\temp\ken\project4\learning.cpp 42 1 project4
Error 7 error C2146: syntax error : missing ')' before identifier 'ticket' c:\temp\ken\project4\learning.cpp 42 1 project4
Error 8 error C2182: 'ticketSort' : illegal use of type 'void' c:\temp\ken\project4\learning.cpp 42 1 project4
Error 9 error C2374: 'ticketSort' : redefinition; multiple initialization c:\temp\ken\project4\learning.cpp 42 1 project4
Error 10 error C2059: syntax error : ')' c:\temp\ken\project4\learning.cpp 42 1 project4
Error 11 error C2143: syntax error : missing ';' before '{' c:\temp\ken\project4\learning.cpp 43 1 project4
Error 12 error C2447: '{' : missing function header (old-style formal list?) c:\temp\ken\project4\learning.cpp 43 1 project4
Error 13 error C2065: 'LOTTERY' : undeclared identifier c:\temp\ken\project4\learning.cpp 64 1 project4
Error 14 error C2146: syntax error : missing ')' before identifier 'list' c:\temp\ken\project4\learning.cpp 64 1 project4
Error 15 error C2374: 'search' : redefinition; multiple initialization c:\temp\ken\project4\learning.cpp 64 1 project4
Error 16 error C2059: syntax error : ')' c:\temp\ken\project4\learning.cpp 64 1 project4
Error 17 error C2143: syntax error : missing ';' before '{' c:\temp\ken\project4\learning.cpp 65 1 project4
Error 18 error C2447: '{' : missing function header (old-style formal list?) c:\temp\ken\project4\learning.cpp 65 1 project4
19 IntelliSense: incomplete type is not allowed c:\temp\ken\project4\learning.cpp 6 6 project4
20 IntelliSense: identifier "LOTTERY" is undefined c:\temp\ken\project4\learning.cpp 6 17 project4
21 IntelliSense: identifier "LOTTERY" is undefined c:\temp\ken\project4\learning.cpp 7 13 project4
22 IntelliSense: declaration is incompatible with "void ticketSort" (declared at line 6) c:\temp\ken\project4\learning.cpp 42 6 project4
23 IntelliSense: identifier "LOTTERY" is undefined c:\temp\ken\project4\learning.cpp 42 17 project4
24 IntelliSense: identifier "LOTTERY" is undefined c:\temp\ken\project4\learning.cpp 64 13 project4