summaryrefslogtreecommitdiffstats
path: root/C++/Sales Array Program/SalesArrayProgram.cpp
blob: 6cd5e7662c660a13c900034529674ad84bacfbd9 (plain) (blame)
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
83
84
85
86
87
88
89
90
91
92
93
94
// Name: msglm
// Date: 
// Program Name:
// Description: 


#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

// Named constants
const int ARRAY_SIZE = 7;

//Func Decl
void printDailySales(double array[]);
double findTotal(double array[]);
double findMax(double array[]);
double findMin(double array[]);

int main() {

	//Variable declaration
    ifstream salesFile;
    double readSales[ARRAY_SIZE];

    //Open file
    salesFile.open("daily_sales.txt");

	//Program title and description for the user
	cout << "Title: 7-day sales calculator" << endl << "Description: Takes in a file with the total income for a day segregated by a newline character. Output is a breakdown of each day's sales, the total for the week, the worst day, and the best day." << endl;

	//Reading input
    for (int pos = 0; pos < ARRAY_SIZE; pos++) {
        salesFile >> readSales[pos];
    }

    //Output
    printDailySales(readSales);
    cout << "Total: $" << findTotal(readSales) << endl;
    cout << "Max: $" << findMax(readSales) << endl;
    cout << "Min: $" << findMin(readSales) << endl;
    return 0;
}

//Prints the daily sales
void printDailySales(double array[]) {
    cout << "Daily Sales Earned: \n";
    for (int pos = 0; pos < ARRAY_SIZE; pos++) {
        cout << "Day #" << pos+1 << ": $" << array[pos] << endl;
    }
}

//Adds up total and returns it as a sum
double findTotal(double array[]){
    double sum = 0;
    for (int pos = 0; pos < ARRAY_SIZE; pos++) {
        sum = sum + array[pos];
    }
        return sum;
}

//Just a classic "find maximum" sorting algorithm
double findMax(double array[]){
    double max = array[0];
    for (int pos = 1; pos < ARRAY_SIZE; pos++) {
        if (max < array[pos]) {
            max = array[pos];
        }
    }
    return max;
}

//classic find minimum sorting algorithm
double findMin(double array[]){
    double min = array[0];
    for (int pos = 1; pos < ARRAY_SIZE; pos++) {
        if (min > array[pos]) {
            min = array[pos];
        }
    }
    return min;
}




	/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
	 *
	 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
	 * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
	 */