// For: https://forum.arduino.cc/t/array-not-printing/1066914
// December 18, 2022
/**********Global Variables**********/
const int metrics_num = 3; // # of financial data metric for employees to track, array row
const int employees_num = 5; // # of employees, array column
int employees_data[metrics_num][employees_num]; // mxn array
int bonus[9]; // # of employee bonus pay ranges
/**********Setup**********/
void setup()
{
Serial.begin(9600);
data_entry(employees_num, employees_data);
pay_calculations(metrics_num, employees_num, employees_data);
}
/**********Main Loop**********/
void loop()
{
}
/**********Function Definition**********/
void data_entry(int n, int data[][employees_num])
{
//enter data for each employee
for (int i = 0; i < n; i++)
{
Serial.print("Enter gross sales for employee ");
Serial.print(i + 1);
Serial.print(": $");
// waits until data is entered into serial monitor
while (Serial.available() == 0) {}
// takes incoming characters and converts it to a number.
// This is read into the buffer altogether.
// Row 1 is contstand, updates column num each pass
data[0][i] = Serial.parseInt();
Serial.println(data[0][i]); // test for printing value entered from array
// flush input buffer, do before asking for new input.
// Notes: https://forum.arduino.cc/t/serial-input-basics-updated/382007
while (Serial.available() > 0) {
Serial.read();
}
}
}
// calculate bonus and fill these into employee data array
void pay_calculations(int m, int n, int data[][employees_num])
{
// Bonus
// multiply each employee data element by bonus %
// store values in Row 2 of array for each element
for (int i = 0; i < n; i++)
{
// Multiplies an employees gross weekly pay by 9% for bonus,
// and stores in Row 2 of employee_data array.
//
// Use a 'float' calculation and then convert it to integer.
// The conversion to integers takes the integer part (rounding down).
float b = (float) data[0][i] * 0.09;
data[1][i] = (int) b;
Serial.print("Empoyee ");
Serial.print(i+1);
Serial.print(", pay: ");
Serial.print(data[0][i]); // test for printing Row 1, column 'n'
Serial.print(", bonus: ");
Serial.println(data[1][i]); // test for printing Row 2, column 'n'
}
}