Program for 5 salaries and averages

This program is for a class and I am having trouble even starting it the question is....

Create a complete C++ program that prompts the user for 5 salary values. Your program should find and print the total of these 5 salaries, and the average of these 5 salaries.
Break your project down into smaller steps and solve each one before moving on to the subsequent step.

Here, you could say the steps are:

- Gather user input
- Calculate and print the total of those salary values (which you collected in step
1): Research arithmetic operators
- Get the average of these 5 salaries (how would you calculate an average in regular math? Same here!)

Let me know if you need any more help,
Joe
Concord Spark Tutor
sparkprogrammer@gmail.com
So I have created this or "found" this but i was told by instructer to use-
(cout << fixed << showpoint;) (cout << setprecision(2);) (ofstream myOutFile;)
(myOutFile.open("lab3output.txt");)

(ifstream salaryFile;) (salaryFile.open("lab3input.txt");)

but all of these statements i have never used and am not sure where to place them?

Thanks for any help!
John



include "<"iostream">"
using namespace std;

main ()
{

int num1,num2,num3,num4,num5;

double averg;

num1=75.35,num2=-35.56,num3=15.76,num4=55.5,num5=10.44;
averg=(num1+num2+num3+num4+num5)/5;

cout <<"average of all three digit is ="<< averg << endl;


cout <<"\n........................"<< endl;
system ("pause");
You've marked this thread as solved. Do you still need help?
Yes I do, I have this so far.


main ()
{


using namespace std;


double salary = 0;
double average = 0;
double total = 0;


cout << "Enter Salary: " << salary << endl;
cin >> salary >> endl;
total=total+salary;

cout << "Enter Salary: " << salary << endl;
cin >> salary >> endl;
total=total+salary;

cout << "Enter Salary: " << salary << endl;
cin >> salary >> endl;
total=total+salary;

cout << "Enter Salary: " << salary << endl;
cin >> salary >> endl;
total=total+salary;

cout << "Enter Salary: " << salary << endl;
cin >> salary >> endl;
total=total+salary;

average=total+salary/5;

cout << "Average of salary: " << average << endl;
cin >> average >> endl;


}


Just to give you an idea...

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
#include <iostream>
#include <iomanip>
#include <fstream>

int main()
{

    std::ofstream outputFile;
    outputFile.open("outputFile.txt");
    double salary{ 0.0 };
    double total{ 0.0 };
    const int maxSize{ 10 };

    std::cout << "Enter " << maxSize << " salary values.\n";
    for (int count = 0; count < maxSize; count++)
    {
	   std::cout << "Salary # " << count + 1 << " : $";
	   outputFile << "Salary # " << count + 1 << " : $";
	   std::cin >> salary;
	   outputFile << salary << std::endl;
	   total += salary;
    }

    double avg = total / maxSize;
    std::cout << std::fixed << std::showpoint << std::setprecision(2);
    outputFile << std::fixed << std::showpoint << std::setprecision(2);
    std::cout << "The average of the " << maxSize << " salaries is $" << avg << std::endl;
    outputFile << "The average of the " << maxSize << " salaries is $" << avg << std::endl;

    outputFile.close();

    return 0;
}
Topic archived. No new replies allowed.