HELP ME

hey guys so I am completely stumped, this is a homework project that I am working on and I dont know how to move forward.

Create a program that reads the file “5HighestPaidAthletes.csv”and outputs the following exactly as it is to the screen AND to a file named “totals.txt”. Again the output to the screen and the file should be identical and appear exactly as the picture below (except dollar amounts may be different).

I am just having isssues around every corner. I am not asking for answers I am asking for someone to look this over and hint me at things to fix. I am new to c++

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
//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;
}
output to the screen and the file should be identical and appear exactly as the picture below

What picture? Example of the input file format would be nice too.

The easiest way to make identical output is to write a function that takes an output stream and results and writes the results to that stream. Call that function twice, once with std::cout and again with outFile.

"Top 5" implies that the input has more than 5 entries. If the first 5 are not the top, then you have to filter somehow.

You don't use the <conio.h> and you don't even want to. Read the sticky thread on this Forum.
closed account (jvqpDjzh)
line 20 or 22:
double salary1, salary2, salary3, salary4, salary5;
Use an array of doubles, I might say, for example: double salaries[5];
Last edited on
Topic archived. No new replies allowed.