- Aug 4, 2002
- 3,030
- 2
- 76
Ok guys so I've been in CS 1361 for about two months now. I thought I'd make this so I could post some of my code and get some feedback.
Lab 25
https://drive.google.com/file/d/0BzD0FjUel2BqdjZCZVFCRnZLbkU/edit?usp=sharing
I can't figure out how to get it to display the correct "highest" and "lowest". Any ideas?
Lab 25
https://drive.google.com/file/d/0BzD0FjUel2BqdjZCZVFCRnZLbkU/edit?usp=sharing
Code:
// Josh
// CS 1361
// Lab 25
// Chips and Salsa Program
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
#define ID "Josh - CS 1361 - Lab 24"
int getLowest(int[], int);
int getHighest(int[], int);
int getTotal(int[], int);
int main()
{
const int ARRAY_SIZE = 5;
string salsa[ARRAY_SIZE] = { "Mild ", "Medium", "Sweet ", "Hot ", "Zesty " };
int sales[ARRAY_SIZE];
cout << ID << endl << endl;
for (int count = 0; count < ARRAY_SIZE; count++)
{
cout << "Jars sold last month of " << salsa[count] << ": ";
cin >> sales[count];
while (sales[count] < 0)
{
cout << "Please enter a valid input for jars sold : ";
cin >> sales[count];
}
}
getLowest(sales, ARRAY_SIZE);
getHighest(sales, ARRAY_SIZE);
getTotal(sales, ARRAY_SIZE);
int highest = getHighest(sales, ARRAY_SIZE);
int lowest = getLowest(sales, ARRAY_SIZE);
int total = getTotal(sales, ARRAY_SIZE);
cout << endl << endl;
cout << " Salsa Sales Report " << endl << endl;
cout << "Name Jars Sold" << endl;
cout << "__________________________________" << endl;
for (int count = 0; count < ARRAY_SIZE; count++)
{
cout << salsa[count] << setw(28) << sales[count] << endl;
}
cout << endl;
cout << "Total Sales: " << setw(21) << total << endl;
cout << "High Seller: " << salsa[highest] << endl;
cout << "Low Seller : " << salsa[lowest] << endl;
return 0;
}
int getLowest(int sales[], int size)
{
int lowest;
lowest = sales[0];
for (int count = 1; count < size; count++)
{
if (sales[count] < lowest)
lowest = count;
}
return lowest;
}
int getHighest(int sales[], int size)
{
int highest;
highest = sales[0];
for (int count = 1; count < size; count++)
{
if (sales[count] > highest)
highest = count;
}
return highest;
}
int getTotal(int sales[], int size)
{
int total = 0;
for (int count = 0; count < size; count++)
{
total += sales[count];
}
return total;
}
I can't figure out how to get it to display the correct "highest" and "lowest". Any ideas?
Last edited:
