Help

I am having an error: error states end1; not identified any help is greatly appreciated


//This program takes the excel document and the data within and produces info
//relating to the salaries of the athletes

// Preprocessor statements
#include <iostream> //for cin, cout, endl
#include <istream>
#include <string>
#include <fstream>
#include <iomanip> //for setprecision
#include <conio.h> // for _getch()
using namespace std; //for cin, cout, endl

int main()
{
//declare variables
ifstream inFile; //input file stream
ofstream outFile; //output file stream

//The variables for the 5 athletes salaries
double salary1, salary2, salary3, salary4, salary5;
//The variables for the 5 athletes Endorsements
double Endorsement1, Endorsement2, Endorsement3, Endorsement4, Endorsement5;
//store the total of the salaries
float totalSalary;
//store the average of the salaries
double avgSalary;
//store the total amount of endorsement
double totalEndorsement;
//store the average amount
double avgEndorsement;
//store the overall cash amount
double totalOverAll;

inFile.open("5HighestPaidAthletes.csv");
outFile.open("totals.txt");

outFile << fixed << showpoint;
outFile << setprecision(4);

inFile >> salary1 >> salary2 >> salary3 >> salary4 >> salary5;
inFile >> Endorsement1 >> Endorsement2 >> Endorsement3 >> Endorsement4 >> Endorsement5;
outFile <<
//add up all the salaries
totalSalary = (salary1 + salary2 + salary3 + salary4 + salary5);
//average the salaries
avgSalary = (totalSalary / 5);
//add up all the endorsements
totalEndorsement = (Endorsement1 + Endorsement2 + Endorsement3 + Endorsement4 + Endorsement5);
//average the Endorsements
avgEndorsement = (totalEndorsement / 5);
//add up totalSalaries and totalEndorsement
totalOverAll = totalSalary + totalEndorsement;
cout << "................................................................\n" << endl;
cout << "ITCS 2530 - Programming Assigmnet for week #2\n" << endl;
cout << "................................................................\n" << endl;
cout << "Of the top 5 highest paid atheletes...\n" << endl;

cout << left << "Total of all salaries: "
<< right << totalSalary << endl;
cout << left << "Average of all salaries: "
<< right << avgSalary << endl;
cout << "\n" << endl;
cout << left << "Total of all Endorsements: "
<< right << totalEndorsement << endl;
cout << left << "Average of all Endorsements: "
<< right << avgEndorsement << endl;
cout << left << "The total of all salries and all endorsements! "
<< right << totalOverAll << endl;

inFile.close();
outFile.close();

return 0;
}
The error I received is around line 42 to 44:
1
2
3
outFile <<
//add up all the salaries
totalSalary = (salary1 + salary2 + salary3 + salary4 + salary5);


After removing outFile << or changing this code to:
1
2
3
//add up all the salaries
totalSalary = (salary1 + salary2 + salary3 + salary4 + salary5);
outFile << totalSalary;


fixed the error and compiled for me. The error the led me to this was:
main.cpp:44:15: error: no viable overloaded '='
                totalSalary = (salary1 + salary2 + salary3 + salary4 + salary5);
                ~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/ostream.tcc:359:25: note: candidate function
      (the implicit copy assignment operator) not viable: no known conversion from 'double' to 'const std::basic_ostream<char>' for 1st
      argument
  extern template class basic_ostream<char>;
= has a lower precedence than <<; use parentheses.
1
2
3
// outFile << totalSalary = (salary1 + salary2 + salary3 + salary4 + salary5);

outFile << ( totalSalary = (salary1 + salary2 + salary3 + salary4 + salary5) ) ;
I changed the input on line 42-44 now I am getting errors stating end1; unidentified.

//This program takes the excel document and the data within and produces info relating to the salaries of the athletes

// Preprocessor statements
#include <iostream> //for cin, cout, end1
#include <istream>
#include <string>
#include <fstream>
#include <iomanip> //for setprecision
#include <conio.h> //for _getch()

using namespace std; //for cin, cout, end1

int main()
{
//declare variables
ifstream inFile; //input file stream
ofstream outFile; //output file stream

//The variables for the 5 athletes salaries
double salary1, salary2, salary3, salary4, salary5;
//The variables for the 5 athletes Endorsements
double endorsement1, endorsement2, endorsement3, endorsement4, endorsement5;
//store the total of the salaries
float totalSalary;
//store the average of the salaries
double avgSalary;
//store the total amount of endorsement
double totalEndorsement;
//store the average amount
double avgEndorsement;
//store the overall cash amount
double totalOverAll;

inFile.open("5HighestPaidAthletes.csv");
outFile.open("totals.txt");

outFile << fixed << showpoint;
outFile << setprecision(4);

inFile >> salary1 >> salary2 >> salary3 >> salary4 >> salary5;
inFile >> endorsement1 >> endorsement2 >> endorsement3 >> endorsement4 >> endorsement5;
outFile <<
//add up all the salaries
totalSalary<< (salary1 + salary2 + salary3 + salary4 + salary5);
//average the salaries
avgSalary = (totalSalary / 5);
//add up all the endorsements
totalEndorsement = (endorsement1 + endorsement2 + endorsement3 + endorsement4 + endorsement5);
//average the endorsements
avgEndorsement = (totalEndorsement / 5);
//add up totalSalaries and totalEndorsement
totalOverAll = totalSalary + totalEndorsement;
cout << ".............................................\n" << end1;
cout << "ITCS2350 - 5 Highest Paid Athletes for week #2\n" << end1;
cout << ".............................................\n" << end1;
cout << "Of the top 5 highest paid athletes......\n" << end1;

cout << left << "Total of all salaries:"
<< right << totalSalary << end1;
cout << left << "Average of all salaries: "
<< right << avgSalary << end1;
cout << "\n" << end1;
cout << left << "Total of all Endorsements:"
<< right << totalEndorsement << end1;
cout << left << "Average of all Endorsements:"
<< right << avgEndorsement << end1;
cout << left << "The total of all salaries and all endorsements:"
<< right << totalOverAll << end1;

inFile.close();
outFile.close();

return 0;

}
Search for end1 and replace it with endl (note: l -> line)
got it last and final error is on line 44 totalSalary
Since you haven't posted using code tags, we can't tell easily which line is line 44.

Also, is there any reason you're choosing not to tell us what the error is? Are you under the mistaken impression that withholding information from us makes it more fun?
The code with the described changes compiles for me with a warning.

On the line:
1
2
//add up all the salaries
totalSalary<< (salary1 + salary2 + salary3 + salary4 + salary5);

You are bit shifting the totalSalary variable. According to the comment above it you should be using the assignment operator.

After fixing that, look at my previous post and JLBorges post to fix the other problem with that line.
I am sorry the error code is C2065 totalSalary undeclared identifier
The warning I receive from my compiler is this:

warning: variable 'totalSalary' is uninitialized when used here
                totalSalary<< (salary1 + salary2 + salary3 + salary4 + salary5);
                ^~~~~~~~~~~
note: initialize the variable 'totalSalary' to silence this warning
        float totalSalary;
                         ^
                          = 0.0


As it says, you can simply replace float totalSalary; with float totalSalary = 0.0; to initilise a float.
Last edited on
Topic archived. No new replies allowed.