Source Code:
#include <iostream>
using namespace std;
struct Employee {
string name;
int age;
float salary;
};
void displayData(Employee);
int main() {
Employee employee[3];
int sizeOfEmployee = sizeof(employee) / sizeof(employee[0]);
for(int i = 0; i < sizeOfEmployee; i++) {
cout << "Enter name for employee " << i + 1 << ": ";
cin >> employee->name;
cout << "Enter age for employee " << i + 1 << ": ";
cin >> employee->age;
cout << "Enter salary for employee " << i + 1 << ": ";
cin >> employee->salary;
}
for(int i = 0; i < sizeOfEmployee; i++) {
displayData(employee[i]);
}
}
void displayData(Employee employee) {
cout << "DISPLAYING INFORMATION" << endl;
cout << "Name: " << employee.name << endl;
cout << "Age: " << employee.age << endl;
cout << "Salary: " << employee.salary << endl;
}
My code doesn't display all the data i've stored into the array, it only reads and display the last data i've inputted.
CODE OUTPUT:
In what way could i possibly get all the data i've stored into the array and display it?
