From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- C++/Sales Array Program/SalesArrayProgram.cpp | 94 +++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 C++/Sales Array Program/SalesArrayProgram.cpp (limited to 'C++/Sales Array Program/SalesArrayProgram.cpp') diff --git a/C++/Sales Array Program/SalesArrayProgram.cpp b/C++/Sales Array Program/SalesArrayProgram.cpp new file mode 100644 index 0000000..6cd5e766 --- /dev/null +++ b/C++/Sales Array Program/SalesArrayProgram.cpp @@ -0,0 +1,94 @@ +// Name: msglm +// Date: +// Program Name: +// Description: + + +#include +#include +#include +#include +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 . + */ + -- cgit v1.2.3