Doing a program for class and I am running into an error any idea where the problem lies?
Code:
The problem says: [Error] expected unqualified-id before '{' token
Programming Assignment:
The client was pleased with their invoice program, and he'd like you to investigate anotherproblem he is running into. He has a text file which has a number of invoices, and would like tohave you read this file, sort it in alphabetical order by last name, and then write it out to a newfile. He would also like the following information on the sorted file: total of balance due, recordwith the customer with the most number of rental days, and the record with the customer withthe highest balance due. For example, the input file would like like the following:
LastName FirstName DaysofRental BalanceDueSmith
Joe 15 100.50
Doe John 10 95.20
Anderson Paul 30 20.00
O'Donell Miriam 10 24.30
Foster Sam 30 15.00
The output file would look like the following:
LastName FirstName DaysofRental BalanceDue
Anderson Paul 30 20.00
Doe John 10 95.20
Foster Sam 30 15.00
O'Donell Miriam 10 24.30
Smith Joe 15 100.50
Total Balance Due for file: 255.00
Customer with the highest number of rental days are : Paul Anderson, Sam Foster
Customer with the highest balance due are: Joe Smith
AssumptionsAssume that the input file1) will never contain records with customers of the same last name.2) is always in the same format, and all records are separated by spaces3) Days in the file are integers4) Balance due will always be a floating point number.5) Names will always have the appropriate casing.6) There will be no interaction from the user. No prompting the user to type in a file name, filename will always have the name "invoice.txt".7) A file could have 1 or more customers with the same balance due, and number of rentaldays. If this is the case, you should write out all records that fit the criteria.8) Assume the file always has 10 records.
INPUTS and OUTPUTSInputs:
Text FileOutputs: Sorted Text File with additional lines for total balance due of file, customers withhighest number of rental days, and customers with highest balance due.
Code:
#include <iostream>#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
struct Invoice{ //structure that represents each invoice
string lastName;
string firstName;
int daysOfRental;
double balanceDue;
}list[10]; //since we can have at most 10
int main(void);
{
ifstream infile("invoice.txt"); //the file that we read the data from
ofstream tofile("answer.txt"); //the file that we write the data to
string line;
getline(infile, line); //we skip the line that has the names of columns
for (int i = 0; i < 5; ++i)
{
infile >> list[i].lastName >> list[i].firstName >> list[i].daysOfRental >> list[i].balanceDue; //read each field of Invoice structure
}
for (int i = 0; i < 4; ++i){ //sort arrays of voices by last name
for (int j = i + 1; j < 5; ++j)
{
string lastname1 = list[i].lastName;
string lastname2 = list[j].lastName;
int x = 0;
for (int k = 0; k < (int)min(lastname1.size(), lastname2.size()); ++k)
{
if (tolower(lastname1[k]) > tolower(lastname2[k]))
{
x = -1;
break;
}
else if (tolower(lastname1[k]) == tolower(lastname2[k]))continue;
else {
x = 1; break;
}
}
if (x == 0)
{
if (lastname1.size() > lastname2.size())
{
x = -1;
}
}
if (x == -1)swap(list[i], list[j]);
}
}
double totalBalance = 0; //total balance of all invoices
vector<pair<string, string> >highestDays;
vector<pair<string, string> >highestBalance;
double maxBalance = 0;
double maxDays = 0;
for (int i = 0; i < 5; ++i)
{
totalBalance += list[i].balanceDue;
if (list[i].daysOfRental > maxDays)
{
highestDays.clear();
highestDays.push_back({ list[i].firstName, list[i].lastName });
maxDays = list[i].daysOfRental;
}
else if (list[i].daysOfRental == maxDays)
{
highestDays.push_back({ list[i].firstName, list[i].lastName });
}
if (list[i].balanceDue > maxBalance)
{
highestBalance.clear();
highestBalance.push_back({ list[i].firstName, list[i].lastName });
maxBalance = list[i].balanceDue;
}
else if (list[i].balanceDue == maxBalance)
{
highestBalance.push_back({ list[i].firstName, list[i].lastName });
}
}
////////write data to the output file
for (int i = 0; i < 5; ++i)
{
tofile << list[i].lastName << " " << list[i].firstName << " " << list[i].daysOfRental << " " << list[i].balanceDue << endl;
}
tofile << endl;
tofile << "Total Balance Due for file: " << totalBalance << endl;
tofile << "Customer with the highest number of rental days are: ";
for (int i = 0; i < highestDays.size(); ++i)
{
tofile << highestDays[i].first << " " << highestDays[i].second;
if (i == highestDays.size() - 1)tofile << endl;
else tofile << ", ";
}
tofile << "Customer with the highest balance due are: ";
for (int i = 0; i < highestBalance.size(); ++i)
{
tofile << highestBalance[i].first << " " << highestBalance[i].second;
if (i == highestBalance.size() - 1)tofile << endl;
else tofile << ", ";
}
return 0;
}