Hi! I'm a novice programmer working on a simple project for my C++ class.
I'm having trouble understanding how to make my program do what I want it to do. Am I on the right track? Or even kind of close?
The full instructions:
Specifications:
1. Use an array to store the sales data. Sales data should be stored as a double.
2. The company has at most 20 locations. (Max capacity of the array)
3. The input file contains a sales report that list the number of stores reporting data and the sales data.
4. Sample Input file format: (samplefile1 and samplefile2)
3
27648.92 234.83 23458.32
The '3' means that this file contains data for three locations. The numbers represent the sales for each location.
5. The main function should be modular so the main tasks must be handled by functions. Note: this is only an outline of the function requirements. You will need to decide on function names, parameter lists and return types on your own.
6. The tasks are:
a. Ask the user for the file name that contains the sales data. Fill the array with the sales data from a file.
b. Total the sales data.
c. Average the sales data.
d. Determine the highest sales in the report.
e. Determine the lowest sales from the report
7. The main function should output the data to the user.
8. Add code to the main function to allow the user to rerun the program.
9. Sample output:
Enter file name: sales.dat
The total sales are $755260.00
The average sales amount is $ 75526.00
The highest sales amount is $124569.00
The lowest sales amount is $ 35678.00
Any help is so appreciated! I am adding a double major in computer science and really love coding - when I understand it....
Best,
Sam
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 76 77 78 79 80 81 82
|
#include<fstream>
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
int main( )
{
int i = 0;
double number;
int size = 20;
double data[size];
ifstream input;
string filename;
cout << "Enter file name: \n";
cin >> filename;
input.open(filename.c_str());
while(input.fail())
{
cout<< "Incorrect.";
}
while (input >> number)
{
data[i] = number;
i++;
}
for(int i = 0; i < size; i++)
{
data[i] = 0;
}
}
double getSalesData(int size, double data[])
{
int i = 0;
double number;
for(int i = 0; i < size; i++)
{
data[i] = 0;
}
}
double getAvg(int size, double data[])
{
double total = 0;
double avg = 0;
for (int i=1; i < size; i++)
{
if(data[i] >=0)
{
total = total + data[i];
}
}
avg = total / data[0];
cout << avg;
return avg;
}
double getHigh(int size, double data[])
{
double high = 0;
for(int i = 1; i < size; i++)
{
if(data[i] > high)
{
high = data[i];
}
}
return high;
cout << high;
}
|