Alright, so I'm trying to make a program that will allow you to enter the sales of 10 employee for three different months each, a desired bonus amount, then have that program display the total amount for each employee then the total for all employees, both with sales and in the bonus.
For some reason, when I run the code below, the array indTotals[10][2] gives me a garbage value.
I remember reading that arrays start at 0, so an array with say, two columns and two rows would actually be using a grid of [0][0], [0][1], [1][0], [1][1]. My issue is when I try to run this code trying to plug values into 0's in the array, it gives me even more garbage than this method. An example of this would be when I set the for loops to say, (i= 0; i<11; i++). To me, I would assume that works. I is set to 0, which is less than 11, so it evaluates to true, making i's value go to 1, then running the loop.
Basically, please tell me where I'm screwing up my array. This is really frustrating me.
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 <iomanip>
using namespace std;
//Prototype Functions
double getBonus();
int main()
{
//Variable Declarations
double personID[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; //One dimensional array used for handling employee IDs.
double indTotals[10][2] = { { 0 }, { 0 } }; //Two dimensional array in which rows identify personID, column 1 identifies total sales, and column 2 identifies total bonuses given.
double personBonus[10][3] = { { 0 }, { 0 } }; //Two dimensional array which will keep track of individual bonuses for each employee for three seperate months.
double bonusRate = 0.0;
double totalSales = 0.0;
double totalBonus = 0.0;
double sales = 0.0;
int i = 0;
//input
cout << "Please enter the desired bonus rate: ";
cin >> bonusRate;
cout << endl;
for (i = 0; i < 10; i++)
{
cout << "Please enter salesperson " << personID[i] << "'s sales for January: ";
cin >> sales;
indTotals[i][1] = indTotals[i][1] + sales;
totalSales = totalSales + sales;
personBonus[i][1] = (sales / bonusRate) + sales;
indTotals[i][2] = indTotals[i][2] + personBonus[i][1];
totalBonus = totalBonus + personBonus[i][1];
cout << endl << "Now enter that salesperson's sales for February: ";
cin >> sales;
indTotals[i][1] = indTotals[i][1] + sales;
totalSales = totalSales + sales;
personBonus[i][2] = (sales / bonusRate) + sales;
indTotals[i][2] = indTotals[i][2] + personBonus[i][2];
totalBonus = totalBonus + personBonus[i][2];
cout << endl << "Now enter that salesperson's sales for March: ";
cin >> sales;
cout << endl;
indTotals[i][1] = indTotals[i][1] + sales;
totalSales = totalSales + sales;
personBonus[i][2] = (sales / bonusRate) + sales;
indTotals[i][1] = indTotals[i][1] + personBonus[i][2];
totalBonus = totalBonus + personBonus[i][2];
}
cout << endl << endl << "Salesperson" << setw(19) << "Total Sales" << setw(19) << "Total Bonus" << endl << endl;
for (i = 0; i < 10; i++)
{
cout << personID[i] << setw(19) << indTotals[i][1] << setw(19) << indTotals[i][2] << endl;
}
system("pause");
return 0;
}
|
EDIT: I'm stupid, essentially, and figured out my issue.