I am trying to store the name,age and wage of data type Emp into an array and ask the user to first input them all and then output them all.
This is what Final wanted output looks like using plain arrays
Number of users to be inputted:3
first one inputted reset*
second one inputted reset*
third one inputted reset*
--------------------------------------------------->>
Displaying information
Name age salary
QWe 69 420
Dvor 42 6900
RT 24 6898
------------------------------------------------------------>>
As for information of three employees inputted.I got a solutions using vectors but can i do it by storing it in arrays
//Current code
// Included header files
#include <iostream>
#include <string>
#include<algorithm>
#include<vector>
using namespace std;
// Global variable declaration
int sized = 0;
// Struct declaration
struct Employee
{
string name;
int age;
double salary;
};
// Protype
void Showinfo(Employee);
int main()
{
// Declaring a variable of type Employee
Employee Emp;
// Inputting the number of employees that are being inputted
cout << "Enter the number of the employees that you want to enter into the database: ";
cin >> sized;
cout << endl << endl;
// Reseting the screen
system("cls");
// For loop to get the name,age and salary of the given number of employees
std::vector<Employee> employees;
for (int i = 0; i < sized; i++)
{
cout << "Enter Full name of employee: ";
cin.ignore();
getline(cin, Emp.name);
cout << endl;
cout << "Enter age of employee: ";
cin >> Emp.age;
cout << endl;
cout << "Enter salary of employee: ";
cin >> Emp.salary;
cout << endl;
employees.push_back(Emp);
system("cls");
}
cout << "Name\t" << "Age\t" << "Wage" << endl;
for (const auto& e : employees) {
Showinfo(e);
}
cout << "\n" << endl;
// Pause the console
cout << "The program has ended" << endl << endl;
system("pause");
return 0;
}
// To display/showcase the information received
void Showinfo(Employee Emp)
{
cout << Emp.name << '\t'
<< Emp.age << '\t'
<< Emp.salary << '\t' << endl;
}
I am trying to get the same output but using an array of type Employee to store the employee information and outputting them without using resizeable arrays/vectors
Like in this code I do need some assistance with a creating a loop that displays the information i do have an array of type Employee declared in global scope after declaring the integer sized.How can i stored these values(Employees info:name,age and salary and output them or is it not possible that way)