Thank you. I changed one thing and I got it to print out the names from the text file. Now I am just trying to figure out how to sort it alphabetically by last name, and again sort it by total sales from largest to smallest.
They did not specify which algorithm I am supposed to use.
I don't work with boolean's to want to even attempt giving myself a bigger headache. However, I modified my code entirely and I think I got up to the sorting by total sales part. Can someone run it and see why it is saying 'i' was not declared in line 80?
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <algorithm> // for std::sort
usingnamespace 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;
}
//
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;
}
]
You don't just have to add braces ... you have to put them in the right place! If two items are in the wrong order (line 104) then you need ALL the following three executable statements to swap them, not just setting temp!
Your linker error tells you that you haven't defined one function, and in cpp.sh, at least, it tells you which one (try it - gear wheel icon at the top right of your code sample). You probably think you have defined that function, but if you look carefully at it then you will find a misspelling.