Collect 2 [Error] Id returned 1 exit status

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

class customer{
      public:
      string first; // represents sequence - string
      string last;
      string state;
      double sHistory[3]; // Sales history for three years.
      double totalSales; // Total sales (adding all three years together)
      int purchaseUnits;
      };
      
void printcust(customer[], int); // voided to show that no actual parameter is there when called.
void sortname(customer[], int); // voided to show that no actual parameter is there when called.
void sortsales(customer[], int); // voided to show that no actual parameter is there when called.


int main () 
{
	
	int i = 0;
		customer custarray[10];
		
		ifstream infile;
		infile.open("infodata.txt");
		
		cout.setf(ios::floatfield); // floating point values are set to fixed
		cout.precision(3);  // specifies the maximum number to be displayed
		
		infile >> custarray[i].first;
		infile >> custarray[i].last;
		infile >> custarray[i].state;
		infile >> custarray[i].sHistory[0];
		infile >> custarray[i].sHistory[1];
		infile >> custarray[i].sHistory[2];
		infile >> custarray[i].purchaseUnits;
	
	
	
	while(infile)
	{
		i++;
		infile >> custarray[i].first;
		infile >> custarray[i].last;
		infile >> custarray[i].state;
		infile >> custarray[i].sHistory[0];
		infile >> custarray[i].sHistory[1];
		infile >> custarray[i].sHistory[2];
		infile >> custarray[i].purchaseUnits;
	
	}
	
	printcust(custarray, i);
	sortname(custarray, i);
	printcust(custarray, i);
	sortsales(custarray, i);
	printcust(custarray, i);
	
	system("pause");
	return 0;
	
}

// sorting by alphabetically by customer last name

	void sortbane(customer custarray[], int numb)
	{
		customer temp;
		
		for(int pass = 0; pass > numb; pass++)
		{
			for(int i=0; i>numb+1; i++)
			{
				if(custarray[i].last > custarray[i].last)
				{
					temp = custarray[i];
				}
				custarray[i] = custarray[i + 1];
				custarray[i + 1] = temp;
			}
		}
			return;
	}
	




// sorting by descending total sales

	void sortsales (customer custarray[], int numb)
	{
		customer temp;
		
		for(int pass = 0; pass>numb; pass++)
		{
			for (int i=0; i>numb-1; i++)
			{
				if (custarray[i].purchaseUnits > custarray[i - 1].purchaseUnits)
				{
					temp = custarray[i];
				}
				
				custarray[i] = custarray[i - 1];
				custarray [i - 1] = temp;
			}
		}
	
	return;
	}
		
	
// printing information of customers

void printcust(customer custarray[], int numb)
{
	cout << "\tFirst" << "\t\tLast" << "\tState" << "\tSales History";
	cout << "\tTotal Sales" << endl;
	cout << setw(50) << "0    1    2" << endl << endl;
	
	for(int i = 0; i<numb; i++)
	{
		cout << setw(12) << custarray[i].first;
		cout << setw(14) << custarray[i].last;
		cout << setw(7) << custarray[i].state;
		cout << setw(5) << custarray[i].sHistory[0];
		cout << setw(5) << custarray[i].sHistory[1];
		cout << setw(5) << custarray[i].sHistory[2];
		cout << setw(6) << custarray[i].purchaseUnits;
		
		custarray[i].totalSales = custarray[i].sHistory[0] + custarray[i].sHistory[1];
		custarray[i].totalSales = custarray[i].totalSales + custarray[i].sHistory[2];
		cout << setw(12) << custarray[i].totalSales << endl;
	}
	return;
		
	}





I got a "[Error] Id returned 1 exit status" what do I do for that? I need help resolving this issue as I have a few hours left to fix it.

Please do not chastise me and simply offer advice.
Last edited on
It would be helpful if you posted the complete error message.

But in this case it seems that you haven't implemented one of your functions, the error message should tell you which one is missing (sortname() maybe?).
Why are you asking the same question twice?

Here and in another topic:

http://www.cplusplus.com/forum/general/260940/2/#msg1133580

Please don't create duplicate topics.
Compile log says this:

Processing C++ source file...
--------
- C++ Compiler: C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\g++.exe
- Command: g++.exe "C:\Users\Anonymous\Documents\IndividualAssignment1.cpp" -o "C:\Users\Anonymous\Documents\IndividualAssignment1.exe" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib" -static-libgcc
C:\Users\ANONYMOUS~1\AppData\Local\Temp\ccagzxKD.o:IndividualAssignment1.cpp:(.text+0x324): undefined reference to `sortname(customer*, int)'
collect2.exe: error: ld returned 1 exit status

You have a typo on line 71:
1
2
// void sortbane(customer custarray[], int numb)
void sortname( customer custarray[], int numb )

Next time, examine (and post, if required) the full text of the error diagnostic:
eg. 'undefined reference to `sortname(customer*, int)'

Make printcust const-correct (add const in both the declaration and the definition).
1
2
// void printcust(customer[], int);
void printcust( const customer[], int );
Line 71: void sortbane(customer custarray[], int numb)

sortbane?
Last edited on
@JLBorges
Thank you. I will next time. I have to get a new computer too because whenever I try to search for little things or even copy my code my computer crashes. Might not be enough to run CPP.

I am just working on sorting the tables now. Thank you.
Topic archived. No new replies allowed.