conversion of vector to an array prgram problem

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
what exactly are you trying to do on line 6 and 7 and I do not even see any vectors. By the way you should put the proper indentations look like you manually removed them so it was all aligned to left which makes it hard to read.
Last edited on
for line 6 i was trying to sort lottery tickets otherwise you can't use binary search
for line 7 i was trying to use bool i.e. if one of the lottery tickets nums are found in the array than its true otherwise it results to false

they were vectors before but i am trying to make it in to an array
how can i do proper indentation. i am sorry i do not know :( can i use the formats on the format list here on this website ?
LOTTERY isn't a data type so you can't use it like one. For example, this
void ticketSort(LOTTERY); is invalid.
Last edited on
yes, they were replaced with
1
2
void ticketSort(vector<int>&);
bool search(vector<int>,int);


i was trying to have an array instead of a vector in the code. LOTTERY is the list of 10 array numbers
Just use spaces for indentation.

Also, LOTTERY is a constant integer, correct? If so, you cannot put a value in a prototype. Prototypes should only have the variable types of what they accept, though you can have default values.
1
2
3
4
5
   //Prototype
void funky(int); //or void funky(int=LOTTERY); for a default value
//...
   //Definition
void funky(int myvar){}


In addition, you are using LOTTERY before it even exists. Another thing to note is that LOTTERY is a local variable, so it only exists within main and your prototypes will never see it.

However, considering how you are using LOTTERY, maybe you meant this?
1
2
3
4
5
6
7
8
9
typedef const int LOTTERY;

void ticketsort(LOTTERY);
bool search(LOTTERY);

int main(){
   LOTTERY lottery = 10;
   //...
}

What LOTTERY is supposed to be is not clear...
Last edited on
Thanks :)
Topic archived. No new replies allowed.