Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- // Prototypes
- int getSalesData(string[], int[]);
- int posOfLargest(int[]);
- int posOfSmallest(int[]);
- void displayReport(string[], int[], int);
- const int SIZE = 5; //Sets a constant, SIZE, to 5. This is then used in the arrays, and sets them all to have 5 columns.
- int main()
- {
- string name[SIZE] = { "Mild ", "Medium", "Sweet", "Hot", "Zesty" }; //Different types of salsa
- int sales[SIZE]; //How many were sold
- int totalJarsSold = getSalesData(name, sales);
- displayReport(name, sales, totalJarsSold); //Calls the displayReport function
- return 0;
- }
- int getSalesData(string name[], int sales[])
- {
- int total = 0; //Total jars sold
- for (int i = 0; i < SIZE; i++)
- {
- cout << "Jars sold last month of " << name[i] << ": ";
- cin >> sales[i];
- while (sales[i] < 0) //Input validation. If a number entered is less than 0, re enter
- {
- cout << "Jars sold must be 0 or more. Please enter again: ";
- cin >> sales[i];
- }
- total += sales[i]; //Adds all the salsas sold together in a variable
- }
- return total;
- }
- void displayReport(string name[], int sales[], int total)
- {
- int mostJarsSold = posOfLargest(sales); //Calls posOfLargest, which sorts them largest to smallest.
- int leastJarsSold = posOfSmallest(sales); //Calls posOfSmallest, which sorts them smallest to largest.
- cout << "Salsa Sales Report" << endl;
- cout << "Name Jars Sold " << endl; //Menu system
- cout << "__________________" << endl;
- for (int i = 0; i < SIZE; i++)
- cout << name[i] << setw(11) << sales[i] << endl;
- cout << "Total sales: " << total << endl; //Menu system
- cout << "Best seller: " << name[mostJarsSold] << endl; //More menu systems
- cout << "Least seller: " << name[leastJarsSold] << endl; //Even more menu systems
- }
- int posOfLargest(int array[])
- {
- int indexOfLargest = 0;
- for (int i = 0; i < SIZE; i++)
- {
- if (array[i] > array[indexOfLargest]) //Sorts them largest to smallest
- indexOfLargest = i;
- }
- return indexOfLargest;
- }
- int posOfSmallest(int array[])
- {
- int indexOfSmallest = 0;
- for (int i = 0; i < SIZE; i++)
- {
- if (array[i] < array[indexOfSmallest]) //Sorts them smallest to largest
- indexOfSmallest = i;
- }
- return indexOfSmallest;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement