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
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void populate_div_sales(float[], string[], int);
int findHighest (float[], int);
void print_result(float[], string[], int);
int main ()
{
int top_div_index = 0;
float div_sales[4];
string div_regions[4];
div_regions[0] = "Northeast";
div_regions[1] = "Southeast";
div_regions[2] = "Northwest";
div_regions[3] = "Southwest";
populate_div_sales(div_sales, div_regions, 4);
cout << "debug print for array div_sales_array" << endl;
for (int i=0; i<4; i++) {
cout << div_sales[i] << endl;
}
top_div_index = findHighest(div_sales, top_div_index);
cout << "debug for top_div_index: " << top_div_index << endl;
print_result(div_sales, div_regions, 4);
return 0;
}
void populate_div_sales(float f_div_sales[], string f_div_regions[], int size) {
for(int i =0; i < size; i++) {
cin >> f_div_sales[i];
while (f_div_sales[i] <= 0) {
cout << "Enter sales for the " << f_div_regions[i] << "division: $";
}
}
}
int findHighest(float f_div_sales[], int top_div_index) {
float greatestSalesAmount = 0;
int save_index = 0;
for(int i = 0; i<index; i++){
if(f_div_sales[i] > greatestSalesAmount){
greatestSalesAmount = f_div_sales[i];
save_index=i;
}
}
return save_index;
}
void print_result(float f_div_sales[], string f_div_regions[], int index) {
cout << "The div with the most sales is " << f_div_regions[index] << " with $" << f_div_sales[index] << " in sales.\n" << "\n";
}
|