Hi,
The array I created contains sales of 5 employees, for a 2x5 array
Row 1 = sales
Row 2 = bonus (bonus = sales * 0.09)
I can get Row 1 populated by entering data. What I'm stuck on is populating Row 2 of bonus data from Row 1.
This codes works
void data_entry(int metrics, int employees, int employees_data[][employees_num])
{
//enter data for each employee
for (int i = 0; i < employees; i++)
{
Serial.print("Enter gross sales for employee ");
Serial.print(i+1);
Serial.print(": $");
while (Serial.available() == 0) {} // waits until data is entered into serial monitor
employees_data[0][i] = Serial.parseInt(); //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
Serial.println(employees_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();}
}
}
This code doesn't work. It doesn't even print the array data from Row 1, which I was able to print in the above code. What could be going wrong?
// calculate bonus and fill these into employee data array
void pay_calculations(int metrics, int employees, int employees_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 < employees; i++)
{
employees_data[1][i] = employees_data[0][i] * 0.09; // multiplies an employees gross weekly pay by 9% for bonus, and stores in Row 2 of employee_data array
Serial.println(employees_data[0][i]); // test for printing Row 1, column 'n'
Serial.println(employees_data[1][i]); // test for printing Row 2, column 'n'
}
}
Full code
/**********Libraries**********/
#include <Arduino.h>
/**********Global Variables**********/
const int metrics = 3; // # of financial data metric for employees to track, array row
const int metrics_count_num = metrics; // don't touch
// may have to make seperate var for passing into array, copy this value
const int employees = 5; // # of employees, array column
const int employees_num = employees; // don't touch
// may have to make seperate var for passing into array, copy this value
const int employees_data[metrics][employees]; // mxn array
const int bonus[9]; // # of employee bonus pay ranges
/**********Function Prototypes**********/
void data_entry(int metrics, int employees, int employees_data[][employees_num]);
void pay_calculations(int metrics, int employees, int employese_data[][employees_num]);
void print_bonus(int metrics, int employees, int employees_data[][employees_num], int bonus[]);
/**********Setup**********/
void setup()
{
Serial.begin(9600);
data_entry(metrics, employees, employees_data);
pay_calculations(metrics, employees, employees_data);
}
/**********Main Loop**********/
void loop()
{
}
/**********Function Definition**********/
void data_entry(int metrics, int employees, int employees_data[][employees_num])
{
//enter data for each employee
for (int i = 0; i < employees; i++)
{
Serial.print("Enter gross sales for employee ");
Serial.print(i+1);
Serial.print(": $");
while (Serial.available() == 0) {} // waits until data is entered into serial monitor
employees_data[0][i] = Serial.parseInt(); //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
Serial.println(employees_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 metrics, int employees, int employees_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 < employees; i++)
{
employees_data[1][i] = employees_data[0][i] * 0.09; // multiplies an employees gross weekly pay by 9% for bonus, and stores in Row 2 of employee_data array
Serial.println(employees_data[0][i]); // test for printing Row 1, column 'n'
Serial.println(employees_data[1][i]); // test for printing Row 2, column 'n'
}
}